Advertisement
aveyo

MicMute

Apr 6th, 2019
5,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.18 KB | None | 0 0
  1. /* 2>nul || title MicMute.bat by AveYo v2019.04.06
  2. @echo off
  3. goto :start
  4.  
  5. :: To undo, open CMD as admin and enter:
  6. reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AppKey\15 /f
  7. reg delete "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map" /f
  8.  
  9. :start
  10. :: Compile MicMute.cs snippet
  11. mkdir %APPDATA%\AveYo 2>nul
  12. pushd %APPDATA%\AveYo
  13. del /f /q MicMute.exe >nul 2>nul
  14. for /f "tokens=* delims=" %%v in ('dir /b /s /a:-d /o:-n "%Windir%\Microsoft.NET\Framework\*csc.exe"') do set "csc="%%v""
  15. %csc% /out:MicMute.exe /target:winexe /platform:anycpu /optimize /nologo "%~f0"
  16. if not exist MicMute.exe echo ERROR! Failed compiling c# snippet & timeout /t -1 & exit /b
  17.  
  18. :: Override APPCOMMAND_LAUNCH_MAIL to toggle MicMute
  19. reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\AppKey\15 /v ShellExecute /d "\"%APPDATA%\AveYo\MicMute.exe\"" /f
  20.  
  21. :: Override ScrollLock key to act as APPCOMMAND_LAUNCH_MAIL
  22. echo YOU NEED TO RUN THE SCRIPT AS ADMINISTRATOR TO REMAP SCROLLLOCK TO LAUNCH_MAIL
  23. reg add "HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout" /v "Scancode Map" /d 0000000000000000020000006ce0460000000000 /t reg_binary /f
  24. echo.
  25.  
  26. echo Now Sign-Off to apply ScrollLock / Launch Mail = MicMute
  27. timeout /t 5 >nul
  28.  
  29. :: Done!
  30. exit/b
  31.  
  32. MicMute.cs */
  33. using System;
  34. using System.Runtime.InteropServices;
  35. using System.Reflection;
  36.  
  37. [assembly:AssemblyTitle("MicMute")]
  38. [assembly:AssemblyCompanyAttribute("AveYo")]
  39. [assembly:AssemblyVersionAttribute("2019.04.06")]
  40.  
  41. namespace MicMute
  42. {
  43.   class Program
  44.   {
  45.     private const int WM_APPCOMMAND = 0x319;
  46.     private const int APPCOMMAND_MICROPHONE_VOLUME_MUTE = 0x180000;
  47.     [DllImport("user32.dll", SetLastError = false)]
  48.     public static extern IntPtr GetForegroundWindow();
  49.     [DllImport("user32.dll", SetLastError = false)]
  50.     public static extern IntPtr SendMessageW(IntPtr hWnd,int Msg,IntPtr wParam,IntPtr lParam);
  51.     static void Main(string[] args)
  52.     {
  53.       try
  54.       {
  55.         IntPtr h = GetForegroundWindow();
  56.         SendMessageW(h,WM_APPCOMMAND,IntPtr.Zero,(IntPtr)APPCOMMAND_MICROPHONE_VOLUME_MUTE);
  57.       }
  58.       catch (Exception)
  59.       {
  60.       }
  61.     }
  62.   }
  63. }
  64. /*_*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement