Solved

Can I use Win 7 Task Scheduler to run a program on shutdown?

Posted on 2014-11-23
10
479 Views
Last Modified: 2014-11-23
I know how to have Task Scheduler run a program.  Can I set it to run a program on shutdown, and then shutdown the system when the program completes?  Better yet, can I set Task Scheduler to run a program on shutdown, but only on certain days of the week and only after a chosen time of day?  I'd prefer to avoid using scripts.  Thanks.
0
Comment
Question by:sjw601
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 19

Assisted Solution

by:Peter Hutchison
Peter Hutchison earned 125 total points
ID: 40460745
You can run a task or program when a specific event occurs. For example, every time you shutdown your computer, it will generate an event e.g.

Event log: System
Source: User32
Event no: 1074

If you create a task based on that event, then yes, you can run a simple task then assuming it can finish on time before services and network is still up.
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 125 total points
ID: 40460777
The combined conditions cannot be used without checking in a script.

First option: A GPO shutdown script (http://technet.microsoft.com/en-us/library/cc770300.aspx) allows for delaying the shutdown process until the script has finished.

Second option: Setup a event triggered task as stated above. The task cannot delay shutdown, though, and might not be able to complete.

In both cases you need to check for other conditions yourself. Date arithmetics are best done in VBS or PowerShell, a .cmd batch is not suited well.
0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 40460783
You could schedule a task based on the shutdown event,
schtasks /Create /RU "username" /RP "password" /SC ONEVENT /D Mon, Wed, Fri /ST 23:59 /TN "Taskname" /TR c:\path-to-program\program.exe"

However in looking at what you are asking, there are some concerns:

Better yet, can I set Task Scheduler to run a program on shutdown, but only on certain days of the week and only after a chosen time of day

You are asking for a level of granularity that is best served with a scripted solution.

First what if the task is set to trigger on the day at the time but no shutdown event is sent ?
Or an event is sent but the time and day criteria are not met ?

What you need would best be served with a solution than can implement logic and also abort any current shutdown request to allow your program to complete then run the shutdown itself.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 69

Expert Comment

by:Qlemo
ID: 40460804
becraig, I don't think you can combine /SC ONEVENT with /D. The Wizard definitely does not allow that.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40460813
That is the point I am making Qlemo in the little bit of chatter beneath it:
First what if the task is set to trigger on the day at the time but no shutdown event is sent ?
Or an event is sent but the time and day criteria are not met ?

Simply stating that the options exist but would not work as expected due to the absence of conditional logic.
0
 

Author Comment

by:sjw601
ID: 40460881
Thanks, everyone!  I think I'll go with a simple shutdown task/script and ignore date and time.  One more question: Task Scheduler will run the program, "xyz.exe."  However, doing so opens the program, but does not actually run it by, for example, clicking "run."  Is there a parameter or something that I can add to the exe or Task Scheduler to make it open the program and invoke "run," so that the program actually accomplished its mission?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 40460906
Of course Task Scheduler runs the application. Are talking about a GUI?
0
 
LVL 29

Accepted Solution

by:
becraig earned 250 total points
ID: 40460907
If I am reading your question correctly, you want to know how to make your program do a specific thing instead of just opening ?

Without more details on what program you are calling there is no easy way to answer that.

I would think there should be parameters you can include in your program to call whatever it is you want to do, however more info on exactly what you plan to cal will help tremendously.
0
 

Author Closing Comment

by:sjw601
ID: 40461024
Thanks everyone.  Yes, the program is a GUI.  I'm in touch with the publisher to see whether I can add a parameter or something so that the opens and runs.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question