Skip to content

Instantly share code, notes, and snippets.

@wizkid057
Last active June 16, 2022 22:53
Show Gist options
  • Save wizkid057/cb918d89a21ae03385d37b3f3f1eebdd to your computer and use it in GitHub Desktop.
Save wizkid057/cb918d89a21ae03385d37b3f3f1eebdd to your computer and use it in GitHub Desktop.
Single instance of windows calculator when using the calculator button on a keyboard with just registry changes (Windows 10)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18]
"ShellExecute"="cmd /c start /min \"\" PowerShell.exe -w h -exec by -comm \"$b=[Scriptblock]::Create((Get-ItemPropertyValue -Path 'Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AppKey\\18\\' -Name Script));Invoke-Command -ScriptBlock $b;\""
"Script"="$w=New-Object -ComObject wscript.shell;$s = '[DllImport(\"user32.dll\")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImport(\"user32.dll\")] public static extern int SetForegroundWindow(IntPtr hwnd);';$x = Add-Type -MemberDefinition $s -Name WindowAPI -PassThru;$r = (Get-Process -Name \"Calculator*\" -ErrorAction SilentlyContinue);$j = $r.ID;$n = $r.Name;if ($r){if($r.MainWindowHandle.ToInt64() -gt 0) {Stop-Process $r -Force;Start-Process -FilePath Calc;}else{$w.AppActivate(\"$n\");}exit 1;}else{Start-Process -FilePath Calc;}exit;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment