How to change Win7 main volume using script?

I want a script for Windows 7, so I can type "vol 50", and the volume will change by 50%, "vol 0" and turn off, etc.

It should be really simple, right?

Apparently, this is not so, and I wasted more than an hour, wading through long explanations of boring things, when people explain the differences between Win 7 and Win XP or between a master volume and other volumes and other things, I tell you what I need .

I found this page: http://msdn.microsoft.com/en-us/library/ms679141.aspx

So I tried to create a test set_vol_50.vbs script that looks like this:

SetMasterVolume 0.5 , NULL 


This results in an error:

 Script: <path>\set_vol_50.vbs Line: 1 Char: 1 Error: Type mismatch: 'SetMasterVolume' Code: 800A000D Source: Microsoft VBScript runtime error 

This is not particularly useful (and not one of them is trying to use Google).
Do I need to somehow throw 0.5 on the float?
Is it wrong to use NULL for the second argument?


I am not married to vbscript for this - all I want to do is global volume level for Windows 7 - as soon as the end result is a simple executable file that can take a percentage, I will be happy.

How can I do it?

+6
source share
1 answer

Someone pointed me to this free tool: http://www.nirsoft.net/utils/nircmd.html

Ultimately, this allows me to create a batch file as follows:

 set /av = 65535 * %1 / 100 C:\path\to\nircmd.exe setsysvolume %v% 

Solves the problem, but a little ugly.

If someone can offer a better solution, I would happily agree with that, but at least I have something that works.

+5
source

Source: https://habr.com/ru/post/887121/


All Articles