Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can VBS be used to modify XP Task Scheduler?

Status
Not open for further replies.

CondorMan

Technical User
Jan 23, 2005
211
GB
Hi everyone

I have XP Pro SP2 on a single laptop. I have a .vbs file that forces a System Restore and I've set Task Scheduler to run it each day at 1800. If the laptop is turned off at 1800, the script doesn't run. Is it possible to modify the details in the Task Scheduler via the .vbs file?

What I'd like to do is set Task Scheduler initially to run the .vbs file "Every 5 minutes from 1800 for 24 hours every day, starting <date>". When the script has done the System Restore, I'd like it to change the details in Task Scheduler to "Every 5 minutes from 1800 for 24 hours every day, starting <date+1>". This would mean that it would run the .vbs file only once each day, at 1800 or as soon as possible after that time.

I don't know if this is possible or, indeed, if there is an easier way to achieve what I need. I'm not keen on using third party software. If I can get this working, I'd like to extend the idea to a routine automatic backup of files to a USB Memory Stick.

Thanks for your time.
 
the Win32_ScheduledJob class from WMI might be of interest
 
That's great - but scary as I know nothing about such things!

I went to the MS site and copied some code (below) into Notepad, saved it with a .vbs extension and ran it. Sure enough, it created the Scheduled Task but the properties were greayed out and it indicated that the job had been created by SYSTEM (rather than me). I'm logged on as my usual name and I have Administrative rights. Can I modify the code to ensure that Task Scheduler indicates that *I* created the job and that the properties *are* available for modification? I also saw that the job was titled "At1" - can I modify the code to name the job something of my choice?

<<<<CODE START>>>>

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("Notepad.exe", "********012500.000000-420", _
True , 4, , True, JobId)
If errJobCreated <> 0 Then
Wscript.Echo "Error on task creation"
Else
Wscript.Echo "Task created"
End If

<<<<CODE END>>>>

I read something about jobs being created in one of two ways not being accessible for editing by the other. I suppose it's possible that this "conflict" accounts for the issues that I have identified.

There is another matter about which I need clarification but, rather than confuse this post, I'll wait a little while before I "throw that into the pot".

Thanks for further input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top