views:

1079

answers:

6

Trying to write a PowerShell cmdlet that will mute the sound at start, unless already muted, and un-mute it at the end (only if it wasn't muted to begin with). Couldn't find any PoweShell or WMI object I could use. I was toying with using Win32 functions like auxGetVolume or auxSetVolume, but couldn't quite get it to work (how to read the values from an IntPtr???).

I'm using V2 CTP2. Any ideas folks?

Thanks!

+1  A: 

You could skin the cat another way by simply managing the Windows Audio Service. Stop it to mute, start it to unmute.

Brian Adams
A: 

Have you seen this question (it reltes to beep, but I'm not sure what sounds you are talking about)?

http://stackoverflow.com/questions/252799/turning-off-the-cmd-window-beep-sound

Ady
A: 

Thanks Brian and Ady, but i would actually like to control the sound level, not disable it altogether. I need a way to do it programmaticaly. Perhaps I need to write an application and call it from PowerShell?

Traveling Tech Guy
+1  A: 

There does not seem to be a quick and easy way to adjust the volume.. If you have c++ experience, you could do something with this blog post, where Larry Osterman describes how to call the IAudioEndpointVolume interface from the platform api(for Vista, XP might be more difficult from what I've found in a few searches).

V2 does allow you to compile inline code (via Add-Type), so that might be an option.

Steven Murawski
+1  A: 

If you can do it in C#, you can do it in PowerShell.

Jay Bazuzi
A: 

I didn't find how to do this in PowerShell, but there is a commandline utility called NirCmd that will do the trick by running this command:

C:\utils\nircmd.exe mutesysvolume 2

NirCmd is available for free here: http://www.nirsoft.net/utils/nircmd.html