Search code examples
c#audiowindows-7pinvokevolume

Mute system from code


I'm trying to mute the PC speaker from my C# console application. I've tried the code suggested on this site and it doesn't affect the volume on my machine. I need the code to work on Win7 and I assume that code only works on XP. I also tried this:

[DllImport("winmm.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public static extern int waveOutSetVolume(IntPtr uDeviceID, int dwVolume);

waveOutSetVolume(IntPtr.Zero, 0);

But when the waveOutSetVolume method is called, the system is not muted and no error are thrown. Is there a way to mute the PC from C# in Win7?


Solution

  • I believe this is what you are looking for. this has been test with windows 7 and also this question as been asked on SO before. Which probably will help you get what you are looking for.