Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I created a batch file to shutdown my PC (Windows 7 Professional).

The batch file is simple, it contains only 1 line:

shutdown -s -t 5

But, sometimes, it does not work.

I use it by using right-click and then "Run as administrator".

Is there any better solution for this?

I need this batch file so I can shutdown my PC while I am connected to it via Remote Desktop. I can turn it on by using wake on lan, but I need a way to completely shut it down remotely!

Thanks :)

share|improve this question

migrated from May 22 '11 at 8:54

This question came from our site for professional and enthusiast programmers.

What do you mean by "But, sometimes, it does not work."? Are you refereeing to the fact that you have to run it as administrator or is it simply not working from time to time? – andvin May 22 '11 at 7:51
Lol, raise your hand if you tested this on your machine! – tofutim May 22 '11 at 8:05
No idea what you mean by why it sometimes doesn't work for you, perhaps you have some unsaved documents open with a dialog box showing. Either way check this out also:… perhaps that will speed up things for you even more. – Grim May 22 '11 at 8:25
@David: It certainly can require administrative rights to shut down a machine. It depends on the group policy configuration. Windows Server does not allow non-administrators to shut down. Non-server versions allow it by default, but it can be changed. – Cody Gray May 22 '11 at 8:40
Why are you looking for a "better" solution than right-clicking on it and running it as administrator? Would you prefer to be told to log out and log back in as an administrator? If you need admin rights to do something, then you need admin rights. There's no workaround unless you own the machine. – Cody Gray May 22 '11 at 8:40

This is not an answer to your direct question, but instead an alternative, and possibly better, way of doing it.

So when you connect in to a computer via Remote Desktop, it removes the Shut Down link from the Start Menu and replaces it with Disconnect or something. However, you can still access the normal shut down functions by pressing Alt + F4 while on the desktop, or after clicking on an empty part of the taskbar.

It should bring up the old fashioned type 'Shut Down Windows' dialog box, with a drop down of all the options you would normally have available in the Start Menu.

This works on 7, Vista and XP.

enter image description here enter image description here

Hope that helps!

share|improve this answer
How in the world would this be a "better" option than what the asker already has? – Cody Gray May 22 '11 at 9:51
@Cody Gray Mainly because it is built into Windows, and works every time. It also doesn't limit you to just the Shut Down function. Lastly, I would say it is also quicker to get to. Clicking the taskbar from whatever program you are in and pressing Alt + F4 is quicker than minimizing everything you have open, finding the file, running it, waiting 5 seconds for the timer etc... – Connor W May 22 '11 at 10:57
The shutdown command is built into Windows, too. If you have the necessary privileges to shut down the machine, either method will work. If not, neither method will work. The shutdown command also doesn't limit you to just shutting down (albeit despite the name). There are flags for restarting, etc. The documentation is here. – Cody Gray May 22 '11 at 11:01
@Cody Gray Yes, I am aware that the 'Shutdown' command is not limited to just the shutdown functionality. But if you wanted to change what the script did, you would have to manually edit it every time, or create multiple scripts, which just gets messy. How is this preferable to using a drop down window that takes much less time to change? – Connor W May 22 '11 at 11:08

If it will help, you can save yourself from having to right click and choose Run as administrator using the Elevation PowerToys from Microsoft. They include a tool that lets you run any command as administrator on a console or in a batch file by simply prepending elevate to any command. (Functionality which really should be shipped with Windows.)

To install this functionality, first download the tools, then run the self-extracting executable and extract them to a directory on disk. Navigate to that directory, right click on ElevateCommand.inf, and select Install from the context menu.

Now, edit your batch file, and prepend elevate to your shutdown command, so it looks like this:

elevate shutdown -s -t 5

Now, you can just double-click on your batch script and UAC will automatically prompt you for administrative approval/credentials, no right-clicking required. It is not possible to bypass this dialog without disabling User Account Control.

share|improve this answer

I would add the -f switch (force) to your batch file. It forces running applications to close, which is what usually stalls a shutdown.

You can also use the Ctrl-Alt-End combination and restart from the bottom right button:

enter image description here

share|improve this answer

Firstly, not sure if you need to be administrator to run it (haven't checked myself).

Some programmes might prevent shutdown, so try using the /f switch

Force running applications to close without forewarning users.The /f parameter is implied when a value greater than 0 is specified for the /t parameter.

share|improve this answer
Well as the script he was using has a /t value of more than 0 (5 in this case), it is already implying the /f switch (as seen in your quote), so explicitly adding won't make a difference. – Connor W May 22 '11 at 11:00

create a batch file, on the desktop with shutdown /p /f and disable uac. Did this to my daughters computer, so she could shutdown in one step. She is high functioning autistic, and needs a simple solution.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.