General discussion

Locked

running a scheduled task programmatically

By shady_azzam ·
Hello,

i'm trying to schedule a task on a windows 2003 system remotely from an XP system using vbscript. I discovered the handy win32_ classes and i wrote this script to try to open notepad remotely using the win32_ScheduledJob class:


Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

objSWbemLocator.Security_.ImpersonationLevel = 3

Set objSWbemServices = objSWbemLocator.ConnectServer _
(strComputer,"root\cimv2", strComputer &"\"& strUser, strPassword)

Set objNewJob = objSWbemServices.Get("Win32_ScheduledJob")

errJobCreated = objNewJob.Create _
("Notepad.exe", schTime, _
False , , , True, JobID)

If errJobCreated <> 0 Then
Wscript.Echo "Error on task creation"
Else
Wscript.Echo "Task created"
End If


I noticed that i was limitted to running a task at a specific UTC time -->schTime (e.g. "********090000.000000-300" - 9AM standard eastern time). This led to problems because on the remote computer the time that the scheduler was setting for the task was always 1 hour off even though the windows clock was set to the right time. I would much rather be able to force a task to run (remotely) after creating it, when i want, or making that task event triggered so that when i trigger a system event remotely the specific task runs. In effect im ignoring the task's scheduled time because it's a hassle.

Any ideas how to accomplish this?

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Running remote scheduled tasks

by Dan Cooperstock In reply to running a scheduled task ...

Create the job on the other system first, but don't schedule it to run. (Do this with the normal Task Scheduler interface, one time.) They use your script to just trigger that job to run right away. No problem.

Back to Web Development Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums