Windows 7 Forums


Reply
Thread Tools

Run batch file on shutdown

 
 
Sid Sid is offline
New Member
Join Date: Jul 2011
Posts: 3
Thanked: 0
 
      07-10-2011
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.
 
Reply With Quote
 
 
 
 
Ace Ace is offline
Established Member
Ace's Avatar
Join Date: Jul 2011
Location: Canada
Posts: 315
Thanked: 56
Send a message via MSN to Ace Ace's Twitter Pag
 
      07-10-2011
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 by Ace; 07-10-2011 at 09:57 AM..
 
Reply With Quote
 
davehc davehc is offline
Super Moderator
davehc's Avatar
Join Date: Jul 2009
Location: Denmark
Posts: 1,867
Thanked: 408
 
      07-10-2011
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.

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
 
Reply With Quote
 
Ace Ace is offline
Established Member
Ace's Avatar
Join Date: Jul 2011
Location: Canada
Posts: 315
Thanked: 56
Send a message via MSN to Ace Ace's Twitter Pag
 
      07-10-2011
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 TrainableMan; 07-10-2011 at 05:44 PM.. Reason: removed assumptions
 
Reply With Quote
 
TrainableMan TrainableMan is offline
^ The World's First ^
TrainableMan's Avatar
Join Date: May 2010
Location: PA, USA
Posts: 4,655
Thanked: 887
 
      07-10-2011
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.
 
Reply With Quote
 
Ace Ace is offline
Established Member
Ace's Avatar
Join Date: Jul 2011
Location: Canada
Posts: 315
Thanked: 56
Send a message via MSN to Ace Ace's Twitter Pag
 
      07-10-2011
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.
 
Reply With Quote
 
davehc davehc is offline
Super Moderator
davehc's Avatar
Join Date: Jul 2009
Location: Denmark
Posts: 1,867
Thanked: 408
 
      07-11-2011
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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script errors running batch file CometLinda Windows 7 Support 0 06-28-2011 06:33 PM
Elmers Batch file writing issue #2 Elmer BeFuddled General Discussion 12 10-25-2010 05:53 PM
Script (Batch File) Writing... Elmer BeFuddled General Discussion 13 06-27-2010 11:47 PM
Running a batch file on shutdown win7 64 bit masplin General Discussion 0 03-21-2010 01:03 PM
Windows 7 install keeps rebooting Stephen47 Installation, Setup and Updates 32 05-24-2009 06:26 PM


All times are GMT +1. The time now is 04:33 AM.
W7Forums is an independent website and is not affiliated with Microsoft Corporation.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33