public static void Mute(bool mute) { // Check if this is vista or XP if (System.Environment.OSVersion.Version.Major >= 6) { EndpointVolume epVol = new EndpointVolume(); epVol.Mute = mute; epVol.Dispose(); } else { int mixerID = 0; if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR) { MIXERLINE line = new MIXERLINE(); line.cbStruct = Marshal.SizeOf(line); line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR) { int sizeofMIXERCONTROL = 152; MIXERCONTROL mixerControl = new MIXERCONTROL(); MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS(); lineControl.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL); lineControl.cbStruct = Marshal.SizeOf(lineControl); lineControl.dwLineID = line.dwLineID; lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE; lineControl.cControls = 1; lineControl.cbmxctrl = sizeofMIXERCONTROL; mixerControl.cbStruct = sizeofMIXERCONTROL; if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR) { mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL)); MIXERCONTROLDETAILS controlDetails = new MIXERCONTROLDETAILS(); MIXERCONTROLDETAILS_BOOLEAN muteValue = new MIXERCONTROLDETAILS_BOOLEAN(); controlDetails.item = 0; controlDetails.dwControlID = mixerControl.dwControlID; controlDetails.cbStruct = Marshal.SizeOf(controlDetails); controlDetails.cbDetails = Marshal.SizeOf(muteValue); controlDetails.cChannels = 1; muteValue.dwValue = Convert.ToInt32(mute); controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue)); Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false); int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE); Marshal.FreeCoTaskMem(controlDetails.paDetails); Marshal.FreeCoTaskMem(lineControl.pamxctrl); } } } } }