GUI script to shutdown and restart the computer

For various (silly) reasons our office has a policy disabling the shutdown & restart buttons on our Windows 7 machines. I am a fan of restarting and shutting down the computer, so thought I should make some shortcuts to allow users to do themselves easily.

It’s easy to restart/ shutdown – just use the shutdown command with the /r or /s switches, or use the Restart-Computer or Stop-Computer cmdlets. But I can’t expect users to do that, so a basic GUI is necessary.

Here’s a script I created:

I must mention that I have no clue designing GUIs with PowerShell. The script is mostly a copy-paste of this with some changes by me (like increasing the height of the box, adding three buttons, checking whether any Outlook/ Word processes are running, etc). The code’s pretty intuitive anyways. Here’s a screenshot of what you get:


I’d suggest placing the script in a location like c:\windows\system32 and creating a shortcut to it. Here’s the shortcut target I used:

It launches a PowerShell process, passes it the script, doesn’t load the profile (-noprofile), doesn’t show the copyright notice (-nologo), hides the window (-windowstyle hidden), doesn’t show a prompt to the user (-noninteractive), and sets the execution policy for that session to RemoteSigned (needed for the script to be executed).

I would suggest putting the shortcut in c:\ProgramData\Microsoft\Windows\Start Menu\Programs so users can find it/ search for in their Start menu.

Update: If you want the default selected button to be “Cancel” instead of “Shutdown” (as is the case above) move the “Cancel” block above the “Shutdown” block. The order of buttons will still be the same as they are decided by the Location property of each object, but since the “Cancel” block is first that will be selected as the default button.