Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mute Windows Volume using C#

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

like image 206
jinsungy Avatar asked Sep 30 '08 17:09

jinsungy


1 Answers

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);
like image 163
Jorge Ferreira Avatar answered Sep 29 '22 01:09

Jorge Ferreira