Solved

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

Posted on 2014-11-23
10
449 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 18

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 68

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 28

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
 
LVL 68

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 28

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 68

Expert Comment

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

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now