Run .BAT file prior to Shut Down?


  1. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
       #1

    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 Computer


  2. Posts : 72,058
    64-bit Windows 11 Pro for Workstations
       #2

    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 Computer


  3. Posts : 90
    windows 7 premium 64 bit
       #3

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

    "Local Computer Policy" User Configuration\Windows Settings\Scripts \logoff
      My Computer


  4. Posts : 2,528
    Windows 10 Pro x64
       #4

    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 Computer


  5. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
    Thread Starter
       #5

    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 Computer


  6. Posts : 90
    windows 7 premium 64 bit
       #6

    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
    Last edited by dsk04; 12 Jan 2012 at 14:12.
      My Computer


  7. Posts : 19,383
    Windows 10 Pro x64 ; Xubuntu x64
    Thread Starter
       #7

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

    Regards,
    Golden
      My Computer


 

  Related Discussions
Our Sites
Site Links
About 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 13:03.
Find Us