views:

5744

answers:

5

Anyone know how to programmatically mute the Windows XP Volume using C#?

A: 

You will probably want to use MCI commands: http://msdn.microsoft.com/en-us/library/ms709461(VS.85).aspx

I should add that while this will give you good general control over the input and output mixers in windows, you may have some difficulty with doing detailed controls, like setting the mic boost, etc.

Oh, and if you're on Vista, then just forget it. It's a totally different model.

+7  A: 

http://www.geekpedia.com/tutorial176_Get-and-set-the-wave-sound-volume.html

marc
This is a well documented tutorial. Nice catch!
Pascal Paradis
Remember that this only works for Windows XP. Under Vista, it will only mute sounds made by the same application, not others.
Martin Plante
A: 

You could use P/Invoke as explained here: http://www.microsoft.com/indonesia/msdn/pinvoke.aspx. It actually goes through the steps in Task 1: Mute and Unmute Sound near the top.

Jim B-G
+1  A: 

I came across this project that might be of interest, if you're running Vista.

itsmatt
+3  A: 

Declare this for P/Invoke:

private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int WM_APPCOMMAND = 0x319;

[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

And then use this line to mute/unmute the sound.

SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr) APPCOMMAND_VOLUME_MUTE);
smink