Hello,

I am trying to develop a script that will adjust the master volume
control on a computer. The best example that I have been able to find
is the following:

Set oShell=CreateObject("Wscript.Shell")
iWait = 1000
oShell.Run "sndvol32"
WScript.Sleep iWait
oShell.AppActivate "Volume Control"
WScript.Sleep iWait
oShell.SendKeys("{TAB}{END}")
WScript.Sleep (iWait/2)
oShell.SendKeys("{PGUP}")
WScript.Sleep (iWait/2)
oShell.AppActivate "Volume Control"
oShell.SendKeys "%{F4}"

Is there something that like an ActiveX object or WMI control that I
can use instead where I can set the volume=10 or 10%?

TIA...

Re: Adjusting Master Volume Level (sndvol32)... by Tom

Tom
Tue Mar 04 14:17:53 CST 2008

On Mar 4, 1:42 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
> Hello,
>
> I am trying to develop a script that will adjust the master volume
> control on a computer. The best example that I have been able to find
> is the following:
>
> Set oShell=CreateObject("Wscript.Shell")
> iWait = 1000
> oShell.Run "sndvol32"
> WScript.Sleep iWait
> oShell.AppActivate "Volume Control"
> WScript.Sleep iWait
> oShell.SendKeys("{TAB}{END}")
> WScript.Sleep (iWait/2)
> oShell.SendKeys("{PGUP}")
> WScript.Sleep (iWait/2)
> oShell.AppActivate "Volume Control"
> oShell.SendKeys "%{F4}"
>
> Is there something that like an ActiveX object or WMI control that I
> can use instead where I can set the volume=10 or 10%?
>
> TIA...

It doesn't appear that the WMI Win32_SoundDevice class has any method
to control the volume. According to MS documentation at MSDN, it only
has two methods, Reset and SetPowerSomething. Neither of which
provides any help.

In addition, SndVol32.exe only has two command line switches, -R to
reset it into record mode and -D to ID a device and no arguments. So
that's a bust, too.

The only thing I can offer is an improved version of your script ...

with CreateObject("Wscript.Shell")
.Run "sndvol32"
do until .AppActivate("Volume") : wsh.Sleep 50 : Loop
.SendKeys "{TAB}{END}" : wsh.Sleep 50
.SendKeys "{PGUP}" : wsh.Sleep 50
.SendKeys "%{F4}" : wsh.Sleep 50
end with

It will take a lot less than three seconds to function. I noted that
on my XP machine sndvol32 opens a control panel with the title of
"Master Volume", so I shortened the title to work with both your
version and my version of the title. I also closed the loop around
the AppActivate to make the process a little more robust.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: Adjusting Master Volume Level (sndvol32)... by Jeff

Jeff
Thu Mar 06 19:30:05 CST 2008

Ouch! Never use SendKeys. It will send keys to the currently active window,
which can change at any time, of course

Jeff

"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:742b2426-49ed-4b3c-9885-df04f0f0cc51@m34g2000hsc.googlegroups.com...
> On Mar 4, 1:42 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
>> Hello,
>>
>> I am trying to develop a script that will adjust the master volume
>> control on a computer. The best example that I have been able to find
>> is the following:
>>
>> Set oShell=CreateObject("Wscript.Shell")
>> iWait = 1000
>> oShell.Run "sndvol32"
>> WScript.Sleep iWait
>> oShell.AppActivate "Volume Control"
>> WScript.Sleep iWait
>> oShell.SendKeys("{TAB}{END}")
>> WScript.Sleep (iWait/2)
>> oShell.SendKeys("{PGUP}")
>> WScript.Sleep (iWait/2)
>> oShell.AppActivate "Volume Control"
>> oShell.SendKeys "%{F4}"
>>
>> Is there something that like an ActiveX object or WMI control that I
>> can use instead where I can set the volume=10 or 10%?
>>
>> TIA...
>
> It doesn't appear that the WMI Win32_SoundDevice class has any method
> to control the volume. According to MS documentation at MSDN, it only
> has two methods, Reset and SetPowerSomething. Neither of which
> provides any help.
>
> In addition, SndVol32.exe only has two command line switches, -R to
> reset it into record mode and -D to ID a device and no arguments. So
> that's a bust, too.
>
> The only thing I can offer is an improved version of your script ...
>
> with CreateObject("Wscript.Shell")
> .Run "sndvol32"
> do until .AppActivate("Volume") : wsh.Sleep 50 : Loop
> .SendKeys "{TAB}{END}" : wsh.Sleep 50
> .SendKeys "{PGUP}" : wsh.Sleep 50
> .SendKeys "%{F4}" : wsh.Sleep 50
> end with
>
> It will take a lot less than three seconds to function. I noted that
> on my XP machine sndvol32 opens a control panel with the title of
> "Master Volume", so I shortened the title to work with both your
> version and my version of the title. I also closed the loop around
> the AppActivate to make the process a little more robust.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/



Re: Adjusting Master Volume Level (sndvol32)... by Tom

Tom
Fri Mar 07 07:20:56 CST 2008

On Mar 6, 8:30 pm, "Jeff Dillon" <jeffdil...@hotmailremove.com> wrote:
> Ouch! Never use SendKeys. It will send keys to the currently active window,
> which can change at any time, of course
>
> Jeff
>
> "Tom Lavedas" <tglba...@cox.net> wrote in message
>
> news:742b2426-49ed-4b3c-9885-df04f0f0cc51@m34g2000hsc.googlegroups.com...
>
> > On Mar 4, 1:42 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
> >> Hello,
>
> >> I am trying to develop a script that will adjust the master volume
> >> control on a computer. The best example that I have been able to find
> >> is the following:
>
{snip}
> >> Is there something that like an ActiveX object or WMI control that I
> >> can use instead where I can set the volume=10 or 10%?
>
> >> TIA...
>
> > It doesn't appear that the WMI Win32_SoundDevice class has any method
> > to control the volume. According to MS documentation at MSDN, it only
> > has two methods, Reset and SetPowerSomething. Neither of which
> > provides any help.
>
> > In addition, SndVol32.exe only has two command line switches, -R to
> > reset it into record mode and -D to ID a device and no arguments. So
> > that's a bust, too.
>
> > The only thing I can offer is an improved version of your script ...
>
> > with CreateObject("Wscript.Shell")
> > .Run "sndvol32"
> > do until .AppActivate("Volume") : wsh.Sleep 50 : Loop
> > .SendKeys "{TAB}{END}" : wsh.Sleep 50
> > .SendKeys "{PGUP}" : wsh.Sleep 50
> > .SendKeys "%{F4}" : wsh.Sleep 50
> > end with
>
> > It will take a lot less than three seconds to function. I noted that
> > on my XP machine sndvol32 opens a control panel with the title of
> > "Master Volume", so I shortened the title to work with both your
> > version and my version of the title. I also closed the loop around
> > the AppActivate to make the process a little more robust.
>
> > Tom Lavedas
> > ===========
> >http://members.cox.net/tglbatch/wsh/

Though I understand your intent, "never" is a fighting word -
especially when you offer no alternative.

Yes, the keystrokes can go astray, but sometimes its still the most
efficient way to do a little task for your own purposes. It probably
should be avoided in any 'production' environment, but I still think
there are a few simple tasks that can benefit from judicial use of
Sendkeys.

Clearly, the 'open-loop' examples generally given in the documentation
are an abomination, but with liberal use of AppActivate to keep the
focus on the right window, it's sometimes just quicker to write a
keystroke driven process than searching for mr. unreliable's
tutorials, as good and helpful as they are, on accessing the system
kernel's APIs - and then finding some reference to the right one - and
then coding it.

Nuf said.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
(Note: This signature was inserted using a Sendkeys routine ;o)

Re: Adjusting Master Volume Level (sndvol32)... by Paul

Paul
Fri Mar 07 09:29:52 CST 2008


"Blue Streak" <rdlebreton@hotmail.com> wrote in message
news:7ee53453-7bc0-4ce2-a0c9-5311cb3ba41c@c33g2000hsd.googlegroups.com...
> Hello,
>
> I am trying to develop a script that will adjust the master volume
> control on a computer. The best example that I have been able to
> find
> is the following:
>
> Set oShell=CreateObject("Wscript.Shell")
> iWait = 1000
> oShell.Run "sndvol32"
> WScript.Sleep iWait
> oShell.AppActivate "Volume Control"
> WScript.Sleep iWait
> oShell.SendKeys("{TAB}{END}")
> WScript.Sleep (iWait/2)
> oShell.SendKeys("{PGUP}")
> WScript.Sleep (iWait/2)
> oShell.AppActivate "Volume Control"
> oShell.SendKeys "%{F4}"
>
> Is there something that like an ActiveX object or WMI control that I
> can use instead where I can set the volume=10 or 10%?

On my system, your sample script sets the volume to 20%. Page up and
down result in 20% changes and the up and down arrows result in 0.2%
changes. So it would take 50 up arrows to get to 10%. I can send 50
up arrow keystrokes with:
oShell.SendKeys("{UP 50}")
but this takes about 5 seconds to complete; any window that pops up
within that time frame could steal those keystrokes.

Perhaps AutoItX control would be more reliable to send those
keystrokes to the window of interest.
http://www.autoitscript.com/autoit3/

-Paul Randall



Re: Adjusting Master Volume Level (sndvol32)... by Jeff

Jeff
Fri Mar 07 12:26:49 CST 2008

Nope, never do that. Bad practice.

"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:c3905aeb-b2fc-4d4c-baca-99981368e36b@m3g2000hsc.googlegroups.com...
> On Mar 6, 8:30 pm, "Jeff Dillon" <jeffdil...@hotmailremove.com> wrote:
>> Ouch! Never use SendKeys. It will send keys to the currently active
>> window,
>> which can change at any time, of course
>>
>> Jeff
>>
>> "Tom Lavedas" <tglba...@cox.net> wrote in message
>>
>> news:742b2426-49ed-4b3c-9885-df04f0f0cc51@m34g2000hsc.googlegroups.com...
>>
>> > On Mar 4, 1:42 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
>> >> Hello,
>>
>> >> I am trying to develop a script that will adjust the master volume
>> >> control on a computer. The best example that I have been able to find
>> >> is the following:
>>
> {snip}
>> >> Is there something that like an ActiveX object or WMI control that I
>> >> can use instead where I can set the volume=10 or 10%?
>>
>> >> TIA...
>>
>> > It doesn't appear that the WMI Win32_SoundDevice class has any method
>> > to control the volume. According to MS documentation at MSDN, it only
>> > has two methods, Reset and SetPowerSomething. Neither of which
>> > provides any help.
>>
>> > In addition, SndVol32.exe only has two command line switches, -R to
>> > reset it into record mode and -D to ID a device and no arguments. So
>> > that's a bust, too.
>>
>> > The only thing I can offer is an improved version of your script ...
>>
>> > with CreateObject("Wscript.Shell")
>> > .Run "sndvol32"
>> > do until .AppActivate("Volume") : wsh.Sleep 50 : Loop
>> > .SendKeys "{TAB}{END}" : wsh.Sleep 50
>> > .SendKeys "{PGUP}" : wsh.Sleep 50
>> > .SendKeys "%{F4}" : wsh.Sleep 50
>> > end with
>>
>> > It will take a lot less than three seconds to function. I noted that
>> > on my XP machine sndvol32 opens a control panel with the title of
>> > "Master Volume", so I shortened the title to work with both your
>> > version and my version of the title. I also closed the loop around
>> > the AppActivate to make the process a little more robust.
>>
>> > Tom Lavedas
>> > ===========
>> >http://members.cox.net/tglbatch/wsh/
>
> Though I understand your intent, "never" is a fighting word -
> especially when you offer no alternative.
>
> Yes, the keystrokes can go astray, but sometimes its still the most
> efficient way to do a little task for your own purposes. It probably
> should be avoided in any 'production' environment, but I still think
> there are a few simple tasks that can benefit from judicial use of
> Sendkeys.
>
> Clearly, the 'open-loop' examples generally given in the documentation
> are an abomination, but with liberal use of AppActivate to keep the
> focus on the right window, it's sometimes just quicker to write a
> keystroke driven process than searching for mr. unreliable's
> tutorials, as good and helpful as they are, on accessing the system
> kernel's APIs - and then finding some reference to the right one - and
> then coding it.
>
> Nuf said.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
> (Note: This signature was inserted using a Sendkeys routine ;o)



Re: Adjusting Master Volume Level (sndvol32)... by Jeff

Jeff
Fri Mar 07 12:35:20 CST 2008

What a hack. How far did you look? 5 seconds searching found many, including

http://www.brothersoft.com/sound-volume-activex-control-24152.html

"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:742b2426-49ed-4b3c-9885-df04f0f0cc51@m34g2000hsc.googlegroups.com...
> On Mar 4, 1:42 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
>> Hello,
>>
>> I am trying to develop a script that will adjust the master volume
>> control on a computer. The best example that I have been able to find
>> is the following:
>>
>> Set oShell=CreateObject("Wscript.Shell")
>> iWait = 1000
>> oShell.Run "sndvol32"
>> WScript.Sleep iWait
>> oShell.AppActivate "Volume Control"
>> WScript.Sleep iWait
>> oShell.SendKeys("{TAB}{END}")
>> WScript.Sleep (iWait/2)
>> oShell.SendKeys("{PGUP}")
>> WScript.Sleep (iWait/2)
>> oShell.AppActivate "Volume Control"
>> oShell.SendKeys "%{F4}"
>>
>> Is there something that like an ActiveX object or WMI control that I
>> can use instead where I can set the volume=10 or 10%?
>>
>> TIA...
>
> It doesn't appear that the WMI Win32_SoundDevice class has any method
> to control the volume. According to MS documentation at MSDN, it only
> has two methods, Reset and SetPowerSomething. Neither of which
> provides any help.
>
> In addition, SndVol32.exe only has two command line switches, -R to
> reset it into record mode and -D to ID a device and no arguments. So
> that's a bust, too.
>
> The only thing I can offer is an improved version of your script ...
>
> with CreateObject("Wscript.Shell")
> .Run "sndvol32"
> do until .AppActivate("Volume") : wsh.Sleep 50 : Loop
> .SendKeys "{TAB}{END}" : wsh.Sleep 50
> .SendKeys "{PGUP}" : wsh.Sleep 50
> .SendKeys "%{F4}" : wsh.Sleep 50
> end with
>
> It will take a lot less than three seconds to function. I noted that
> on my XP machine sndvol32 opens a control panel with the title of
> "Master Volume", so I shortened the title to work with both your
> version and my version of the title. I also closed the loop around
> the AppActivate to make the process a little more robust.
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/