Scheduled Tasks: Change Start Times

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Scheduled Tasks: Change Start Times

Post by jstevens »

I'm not sure if this should be posted to Excel or Windows 7. Please feel free to move it if necessary.

Is it possible to programatically through Excel VBA to change the start times of Scheduled Tasks as well as "run them now". And also to enable/disable them.

I have about 30 Scheduled Tasks that I would like to maintain via an Excel workbook and VBA.

Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78509
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Scheduled Tasks: Change Start Times

Post by HansV »

I have moved this topic to the VB/VBA forum since you want to edit and run scheduled tasks from VBA.
Best wishes,
Hans

User avatar
John Gray
PlatinumLounger
Posts: 5408
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Scheduled Tasks: Change Start Times

Post by John Gray »

You might want to look at the command line program SCHTASKS, specifically at the help from SCHTASKS /change /?
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Scheduled Tasks: Change Start Times

Post by jstevens »

Using the command lines for creating a Scheduled Task, I can execute Excel but am having difficulty with the argument to open a particular Excel file.

Within the command line I'm using this: /tr "c:\program files (x86)\microsoft office\office11\excel.exe" "d:\myExcelFile.xls"

My Operating System is Windows 2007. If I create the task manually it works. My challenge is around the arguement "d:\myExcelFile.xls" which doesn't seem to pass through the command line.

Thanks for taking a look,
John
Regards,
John

Becks
2StarLounger
Posts: 196
Joined: 31 Mar 2011, 03:41
Location: Perth, Western Australia

Re: Scheduled Tasks: Change Start Times

Post by Becks »

Does /tr "c:\program files (x86)\microsoft office\office11\excel.exe /r d:\myExcelFile.xls" work?


Regards
Kevin

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Scheduled Tasks: Change Start Times

Post by jstevens »

Kevin,

Your suggestion did not work. I was able to create a scheduled task based on John Gray's suggestion of using the SCHTASKS command line.

Upon editing the scheduled task I find the path to the Excel exe file being parsed to the argument line. I tried putting quote marks around the path but it still parses.
untitled.png
Regards,
John
You do not have the required permissions to view the files attached to this post.
Regards,
John

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Scheduled Tasks: Change Start Times

Post by jstevens »

The resolution is to use the escape sign "\" between quotes.

Example:

Code: Select all

schtasks /create /tn "My App" /tr "\"C:\Program Files (x86)\Microsoft Office\OFFICE11\excel.exe\" \"D:\MyExcelFile.xls"\" /sc once /sd 09/23/2011 /st 00:00


Regards,
John
Regards,
John

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Scheduled Tasks: Change Start Times

Post by jstevens »

I have one more question regarding the SCHTASKS setting for power. I'm working on a laptop and running on the battery not AC. I have found that creating a scheduled task from code defaults the power setting to only run if connected to AC. I'd like to turn that feature off with code. I know I can do this manually but it defeats the purpose of doing everything by code.

One more thing...the scheduled task created will not run until I either plug into AC or disable the power setting manually.

Thanks for your suggestions,
John
Regards,
John