I'm using a shortcut with a powershell command line for shutting down the monitor. It does what it has to do except automatically close the powershell window after the rule is executed.
How do I change the command line so that the window closes automatically?
This is the command line I'm using:
powershell.exe -Command "(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd,int hMsg,int wParam,int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"
CodePudding user response:
Solution 1: Add '; exit' after the first command, telling PowerShell there is an additional command.
powershell.exe -Command "(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd,int hMsg,int wParam,int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"; exit
Solution 2: If the first example does not work you can tell cmd to pass your command into a PowerShell process, if the shortcut is not acting properly.
C:\Windows\System32\cmd.exe /c powershell.exe -Command "(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd,int hMsg,int wParam,int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)" & exit