Script to shutdown Windows 7 PC

2

2

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 :)

ewlung

Posted 2011-05-22T07:41:53.797

Reputation:

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? – None – 2011-05-22T07:51:47.260

1Lol, raise your hand if you tested this on your machine! – None – 2011-05-22T08:05:47.537

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: http://www.instructables.com/id/Make-the-shutdown-icon-on-your-desktop-and-others./ perhaps that will speed up things for you even more.

– None – 2011-05-22T08:25:16.030

@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 – 2011-05-22T08:40:04.563

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 – 2011-05-22T08:40:59.803

@Grim: How can that speed things up even more? That's exactly the same thing as he has now. Except, instead of 5 seconds, it waits 10 seconds before initiating a shutdown. That's slower by definition. – Cody Gray – 2011-05-22T08:42:01.583

Answers

2

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!

Connor W

Posted 2011-05-22T07:41:53.797

Reputation: 3 537

1How in the world would this be a "better" option than what the asker already has? – Cody Gray – 2011-05-22T09:51:33.737

@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 – 2011-05-22T10:57:54.293

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 – 2011-05-22T11:01:21.527

@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 – 2011-05-22T11:08:22.480

2

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

John T

Posted 2011-05-22T07:41:53.797

Reputation: 149 037

1

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.

Patches

Posted 2011-05-22T07:41:53.797

Reputation: 14 078

0

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.

James

Posted 2011-05-22T07:41:53.797

Reputation: 1 185

1Well 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 – 2011-05-22T11:00:47.930

0

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.

Steveebey73742

Posted 2011-05-22T07:41:53.797

Reputation: 1