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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Task Scheduler

Status
Not open for further replies.

pytchley

Technical User
Jan 20, 2003
123
GB
How can I enter a caption for a scheduled task. I have used the following code from MS Script repository but it creates a caption of AT1 then AT2 etc if it already exists.
I want a description that refects the task.
Here is the code:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("Notepad.exe", "********123000.000000-420", _
True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated
 
Hello pytchley,

.Caption is read-only only once the job is actually created. Hence to specify your Caption, I would set it before the .create.

Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
objNewJob.Caption="my caption string"
errJobCreated = objNewJob.Create _
("Notepad.exe", "********123000.000000-420", _
True , 1 OR 4 OR 16, , , JobID)

regards - tsuji
 
Sorry tsuji
That appears to be unsupported for the object as it comes up with
'Object required: objNewJob.Caption'

Regards Pytchley
 
Hello again,

It is I who feel really sorry. The way won't work. .Caption seems read-only and be something inherited from the parent or else being a device for future implementation.

I checked the cim studio. The caption property is there. I am a bit surprised that you get that error "Object required" thing. My testing seems go through all right. Only that when Get the job back from the collection, the caption was not set, had not created as instructed.

My wild guess would be that a lot of built-in properties are still not fully implemented or just reserved for future development---a thing to watch. The present implementation of win32_scheduledjob seems not doing anything more than the "at" commandline. Besides, documentation is scare, so I cannot learn much from others. Any other insight, Pytchley?

regards - tsuji
 
Upon reflexion, you had probably putting Set in front of the .Caption line I proposed. Taken that the attempted assigning string to it does not work it way to the job created, the .caption itself is a valid documented property.

For the sake of sharing info, I suggest you can run the following script to have a complete list of its properties available.

'--------
Set oJob=GetObject("winmgmts:Win32_ScheduledJob")
strList=""
for each Property in oJob.Properties_
strList=strList&Property.Name&vbcrlf
next
wscript.echo strList
'--------

-tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top