I want a script for Windows 7 so I can type "vol 50" and the volume gets changed to 50%, "vol 0" and it mutes, and so on.
This should be really simple, right?
Apparently, it's not, and I've wasted over an hour wading through various long explanations of boring things where people are explaining differences between Win 7 and Win XP or between master volume and other volumes, and various other things that aren't telling me what I need.
I found this page: http://msdn.microsoft.com/en-us/library/ms679141.aspx
So I tried creating a test set_vol_50.vbs script that looks like this:
SetMasterVolume 0.5 , NULL
This results in the error:
Script: <path>\set_vol_50.vbs
Line: 1
Char: 1
Error: Type mismatch: 'SetMasterVolume'
Code: 800A000D
Source: Microsoft VBScript runtime error
Which isn't particularly helpful (and neither is trying to google on that).
Do I need to cast 0.5 to a float somehow?
Is NULL the wrong thing to use for the second argument?
I'm not married to vbscript for this - all I want to do is globally set the master audio volume for Windows 7 - once the end result is a simple executable that can accept a percentage, I'll be happy.
How do I do it?
Someone pointed me towards this freeware tool: http://www.nirsoft.net/utils/nircmd.html
Which ultimately allows me to create a batch file like this:
set /a v = 65535 * %1 / 100
C:\path\to\nircmd.exe setsysvolume %v%
Which solves the problem, but is a bit ugly.
If someone can provide a better solution, I'll happily accept it over this, but at least I've got something which works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With