Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Run .BAT file prior to Shut Down?

07 Jan 2012   #1
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 
Run .BAT file prior to Shut Down?

G'day,

I'm trying to find out if it is possible to use Task Scheduler to run a .BAT file (for backing up data) and then shut the PC down as soon as I click the Start Orb > Shut Down button.

Essentially, I want to use the Shut Down button as a trigger to invoke the .BAT file, and then for the PC to shut down once the .BAT file has completed.

I've searched a few tutorials, and looked at the Task Scheduler help, but I can't find out how to do this. Can anyone offer any suggestions?

Regards,
Golden


My System SpecsSystem Spec
.
07 Jan 2012   #2
Brink

64-bit Windows 10 Pro
 
 

Hello Golden,

It may be easier to create a BAT file to do the backup and shut down the computer after X amount of time when it's ran instead. This way you could create a shortcut of the BAT file, and pin it to say the taskbar to make it easy to use.

Hope this helps some,
Shawn
My System SpecsSystem Spec
07 Jan 2012   #3
dsk04

windows 7 premium 64 bit
 
 

you need windows pro or greater , start /run "gpedit.ms"

"Local Computer Policy" User Configuration\Windows Settings\Scripts \logoff
My System SpecsSystem Spec
.

07 Jan 2012   #4
cluberti

Windows 10 Pro x64
 
 

Yup - use a computer shutdown script. Given your specs say you're using Win7 Ultimate, you should be able to do this in gpedit under Computer Config > Windows Settings > Scripts.
My System SpecsSystem Spec
12 Jan 2012   #5
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

Guys,

Apologies for not replying sooner ... I've been playing with Linux for a bit.

Unfortunately, I forgot to mention that this is for a system running Home Premium, so I can't use the GPEDIT route and will have to go the shutdown route in the .BAT as suggested by Brink. Just one more question:

If I implement the following:

Code:
xcopy E:\Data\*.xlsx Z:\Backups\*.xlsx
shutdown /s
Will shutdown only be executed once the xcopy has been completed entirely? I'm inclined to think so, since its a batch file, and commands are executed sequentially. Or, is it safer to run:

Code:
xcopy E:\Data\*.xlsx Z:\Backups\*.xlsx
shutdown /t:60
Thanks,
Golden
My System SpecsSystem Spec
12 Jan 2012   #6
dsk04

windows 7 premium 64 bit
 
 

if you use something like autoit you can use a runwait and youll get be able to use yout first code and even have the code copy the files you need with no worry about timing,

your first bat will work and execute after it copy's
My System SpecsSystem Spec
13 Jan 2012   #7
Golden
Microsoft MVP

Windows 7 Ult. x64
 
 

Thanks, I've tested both options for shutdown, and both work as expected.

Regards,
Golden
My System SpecsSystem Spec
Reply

 Run .BAT file prior to Shut Down?




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
BSOD - Occurs during Shut Down Process. Shut Down hangs then crashes
Hey there, Lenovo E440 that ran excellent until recently. About a week or two ago I got an error message about a power surge on a USB port. Didn't really seem to effect much so I moved on. Lately, when shutting down, it hangs for a few minutes... just sitting at the final "Shutting Down"...
BSOD Help and Support
Had to force shut down, BSOD after. Created dump file restarts okay.
HP DV7 6143cl Windows® 7 Home Premium with Service Pack 1 (64-bit) I had something hang up and prevented shutdown so I forced shutdown and of course a blue screen occurred afterwards. A couple of days before the 'hang up - forced shutdown - blue screen' I noticed high CPU usage and the fan...
BSOD Help and Support
How to get the open this file message to shut up?
Everytime I download a app off the internet windows always asks me would you like to open this file and it is so annoying!!! How the **** do you get this message to shut up!
Software
Prior drive - sharing
Hey all, new here and did some searching but my problem is unique and hope there's a work around. My prior PC failed about 2 weeks ago. Would not boot. The HD in that PC was partitioned 4X (300 GB Maxtor) with pics and music stored on the partitions but because other family come over and share...
Hardware & Devices
PPPoE Prior to Login
Hey all, I am running Windows 7 Ultimate and I connect directly to the internet via my providers modem. I am not using a router and would rather not. It's just a straight through connection. In order to connect to the internet the PPPoE connection has to be dialed but this doesn't work well...
Network & Sharing
questions prior to upgrading
Hi. I'm currently running windows xp sp3. I apologise for the long post but i have a number of questions prior to taking the plunge and upgrading to windows 7 - the more i read the more nervous i get. I am an average home user not really tech savvy but not a technophobe either. 1. my computer...
Installation & Setup


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 03:27.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App