Skip to content

Instantly share code, notes, and snippets.

@enyone
Created November 17, 2025 17:52
Show Gist options
  • Select an option

  • Save enyone/8ee1d1f48cd366e184acccdf3512c41d to your computer and use it in GitHub Desktop.

Select an option

Save enyone/8ee1d1f48cd366e184acccdf3512c41d to your computer and use it in GitHub Desktop.
Windows microphone mute toggle code
using System;
using System.Runtime.InteropServices;
namespace Mic {
class Mute {
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")] public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private const int WM_APPCOMMAND=0x319;
private const int APPCOMMAND_MICROPHONE_VOLUME_MUTE=0x180000;
public static void MicMute(IntPtr h) {
SendMessageW(h, WM_APPCOMMAND, h, (IntPtr)APPCOMMAND_MICROPHONE_VOLUME_MUTE);
}
static void Main(string[] args)
{
MicMute(GetForegroundWindow());
}
}
}
@enyone
Copy link
Author

enyone commented Nov 17, 2025

Build with:

csc.exe /t:exe /out:MicMute.exe MicMute.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment