Run batch file on shutdown


Sid

Joined
Jul 10, 2011
Messages
3
Reaction score
0
I want to run a batch file on shutdown of pc.I hav Windows 7 Basic edition, so it does not have gpedit.msc.So,please suggest some other methods to do it.
 

Ace

Microsoft MVP
Joined
Jul 7, 2011
Messages
314
Reaction score
61
What is this batch file going to do exactly?

If it doesn't get a chance to run before your computer forces a shutdown it won't do you good. Is this a temp file cleaner script or?

I know how to program an executable to intercept the windows message for a shutdown to postpone it for a set wait time, and run a script. But i've never needed it as I don't like my shutdown process taking up extra time, and I don't need to clean files on every shutdown from temp /prefetch / etc.. folders.

Running CCleaner works fine for me when I use it manually.

But i'm going to need some more information before I can help you here.

---------------------------------------------------------------------------------------------------

I believe you can change the shutdown script command through the root console.

• {Windows Key} + R to open the Run command
• Type in "mmc" and press enter
• File > Add/Remove Snapin
• Choose Group Policy
• Choose default local computer
• Local Computer Policy - Computer Config > Windows Settings > Scripts > Shutdown
• Point it to the location of your batch script file.

---------------------------------------------------------------------------------------------------

I know the above method works, but for you since you have Home Basic, i'd suggest creating a batch file that calls to shutdown.exe after you run the contents of your regular/original batch script. Place it on your desktop, and use it instead of the Start> Shutdown method.
 
Last edited:
Ad

Advertisements

davehc

VIP Member
Joined
Jul 20, 2009
Messages
1,958
Reaction score
502
Gpedit.msc, is a convenient graphical interface to the registry. You can edit the registry direct, if you feel capable.Make a backup of your registry before proceeding, we can all mistype!
Try this.
Open “regedit” (run as administrator.)
Scroll to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control and double click WaitToKillServiceTimeout entry on the right side and change its value to 5000 - NO lower.
http://techdows.com/wp-content/uploads/2010/07/shutdownWindows7faster.png
3.Go to HKEY_CURRENT_USER\Control Panel\Desktop , right click "DeskTop "and create a new Keyon the right pane create new string value named WaitToKillAppTimeout and give its value as 5000.If that string already exists then double click it and enter its value also, as 5000.
Please don’t enter any lower values as the programs need a minimum to close.
Restart your Computer for changes to take affect see if there is an improvement.

You can also create a command line shortcut on your desktop:.
shutdown /f /s /t 0
 

Ace

Microsoft MVP
Joined
Jul 7, 2011
Messages
314
Reaction score
61
Just an added note for clarity ... it is recommended that the registry back-up be stored on the same drive as your OS files. I have a folder for example in my C:\ drive called "RegBackups". [paragraph edited by TM]

this allows for easier merging if you need to revert to a previous "state" with a reg file export.

But I believe he wants to execute a batch file on the event of shutting down his computer. This won't really achieve that I don't believe.

In Group Policy itself I know how to point the shutdown script command to a batch script, but not sure since i've never had a version of Windows below HomeBasic, which doesn't allow you the privillege of gpedit.

Since it is a batch script though, what he could do is take his original script and put it before the command line to shut down his computer in the .bat file. Then all he'd need to do is use that to shut down his computer instead of the regular power button. (Start menu)
 
Last edited by a moderator:

TrainableMan

^ The World's First ^
Moderator
Joined
May 10, 2010
Messages
9,314
Reaction score
1,583
Yes, group policy simply edits keys in the registry but unfortunately it often adds entire sections of information that would be tedious to find otherwise.

Ace mentions the other issue that your shutdown may be interrupted by the shutdown procedures timeout and Dave has shown where you can adjust that timeout.

So you could combine their ideas and have a batch file that ends with shutdown /f /s /t 0 but you would have to run it manually from a desktop icon as opposed to having it built into the normal shut down procedure. Personally, if I was going to have an icon on my desktop for shutdown, I would also build-in a "Shutdown: are you sure?" into the script just in case someone clicks it by accident.
 

Ace

Microsoft MVP
Joined
Jul 7, 2011
Messages
314
Reaction score
61
Thats the one downside. I know a while back I was trying to figure out what the values were for the start menu icons and items, but it was one of these kinds of keys after extensive tests I did:

{EA8D0-JLKJ0- etc....

The greater the chance that you'll hit the wrong key and make unwanted changes.
 
Ad

Advertisements

davehc

VIP Member
Joined
Jul 20, 2009
Messages
1,958
Reaction score
502
It would be an advantage to hear from the OP as to what he wishes to do??

Maybe he could find all he needs by typing Shutdown help in a Command prompt?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top