set oshell=createobject("wscript.shell")
oshell.run "sndvol32"
oshell.appactivate "volume control"
wscript.sleep 100
oshell.sendkeys "{tab}+{tab}"
oshell.sendkeys "m "
oshell.appactivate "volume control"
wscript.sleep 100
oshell.sendkeys "%{f4}"
Which is clumsy at best and won't work at worst. With the above example you are using the Master Volume app in Windows, just like you like you would if you launched it from the Windows menu. The only difference is that script launches the master volume control and uses VBScript sendkeys to check the mute checkbox.
This has the effect of the Master Volume control launching and then the invisible hand of sendkeys clicking the mute checkbox.
Aside from the distraction of the Master Volume app launching abruptly, this method also has to be timed just right otherwise the sendkey method may send the keystroke to another application entirely. I for one, never like to rely on sendkey when there is a possibility it may not work.
A more desirable option to Mute Window Volume... a simple Vbscript that use the keycode sent from the mute button on some keyboards.
Keyboards that include a mute button on the keyboard are able to toggle between mute and unmute. If we knew the keycode that the keyboard mute button was sending to Windows we could use that in our VBScript.
But how to find the keycode? Well a few minutes on Google and you can find a solution :). Here's one in Visual Basic 6 (seems appropriate since some Vbscript'ers may be familiar with the mother launguage) http://vbnet.mvps.org/index.html?code/hooks/lowlevelkeyboardproc.htm Just modify it slightly to display the keycode. Well, it doesn't take long to find that when we press the mute button on a keyboard, that has a mute button, the keycode is 173. Great now just create a VBScript that sends keycode to Windows.
Here's the script that just sends a simple keycode to windows to mute or un-mute the master volume...
set oShell = CreateObject("WScript.Shell")
oShell.SendKeys chr(173) 'toggle between mute and un-mute
Yep, just two lines of code. Open notepad, copy the two lines and save it to a file named 'mute.vbs'. Now when you double click on the mute.vbs file it will mute and un-mute the master volume.The advantages of the new script are many but I'll summarize with the most important differences. The old script launched the Master sound volume and had to time the sendkeys just right otherwise it failed. The new script always works!
Works with Windows from Windows 98 to Vista and probably Windows server 2008 too. :)
Enjoy.
Dennis Robins
http://www.windows-password-reset.com/
Dennis Robins
http://www.windows-password-reset.com/
BRILLIANT! Thanks!
ReplyDeletestill works in Windows 10
ReplyDeleteLOL