Hi,

Does anybody knows how to modify the "Advanced properties" of a scheduled task using VB script.
My requirement is to go to the "Settings tab" then go to "Schedule task completed" and change the check box of "delete the task if it is not scheduled to run again"
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

-2
Google took 0.23 seconds to find an example. http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/taskscheduling/

Entering the WMI class name got me this http://msdn.microsoft.com/en-us/library/aa394399(VS.85).aspx in 0.3 seconds.

Keep the Google thing secret for now, eh? Otherwise, everyone will start using it.
Answered 03/24/2009 by: VBScab
Red Belt

Please log in to comment
0
Hi VBScab,
You are a awesome guy. I didn't knew you have such a great talent to copy from google :)
However if you see my post you forgot to run my VB script or didn't had enough time to read my script.
My script uses SCHTASKS.exe which is a replacement for AT.exe by Microsoft. The link which you gave for "Win32_ScheduledJob Class" is for AT.exe
Even though if I use AT.exe still it doesn't help me to Append the advanced settings of a created Schedule. i.e Power Management and schedule task completed modifications.

For your kind information I had gone through the links provided by you, very back before posting on to Appdeploy. I would suggest you to first study my requirement and then reply instead of just poking around. Thanks for your precious time.
Answered 03/25/2009 by: neel.login
Senior Yellow Belt

Please log in to comment
0
However if you see my post you forgot to run my VB script or didn't had enough time to read my script
What script? You didn't post one.

I will contribute a significant sum to any charity of your choice if you can tell me where in this text:Does anybody knows how to modify the "Advanced properties" of a scheduled task using VB script.
My requirement is to go to the "Settings tab" then go to "Schedule task completed" and change the check box of "delete the task if it is not scheduled to run again"
you mention that you're not using the built-in scheduler? Or that you already Googled for a solution?

Next, it's always a good idea to argue your point from a position of strength. The WMI_ScheduledJob class doesn't care what command line tool is used to access the relevant API, since that class itself abstracts that API and doesn't use the command line. Googling for 'SCHTASKS.exe +wmi' got me to http://www.microsoft.com/technet/scriptcenter /resources/qanda/sept04/hey0922.mspx where you'll see that confirmed. Still, those guys probably don't know what they're talking about, either.

Lastly, you seem to be right about direct access to the 'Advanced' settings, certainly as far as browing the class's properties and methods goes. However, some logical thought around the properties to which you do have access would probably provide a solution. That is, your script could calculate whether or not the task is scheduled to run again (using VBS's Now() and the class's UntilTime property and, if it's not scheduled, use the class's Delete method to delete it.
Answered 03/25/2009 by: VBScab
Red Belt

Please log in to comment
0
Thanks for you thoughts.

Please see attached snapshot attached image for my requirement. Also my script below:

Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("Process")
SysDrive = WshEnv("SYSTEMDRIVE")
SysRoot = WshEnv("SYSTEMROOT")
Password = YourPasswordHere
JobName = WSUS
chkSched()
Sub chkSched()
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")

'checks for pre-existing job
If not fso.fileExists(sysroot & JobName) then
'creates it if it doesnt exist
runDate = setFileDate()
WScript.Echo runDate
schedule = "SCHTASKS /Create /SC once /TN wsus /TR ""C:\Path\Scipts\wsus.vbs"" /ST 18:00:00 /RU domain\Username /RP " & password & ""
return = WshShell.Run(schedule, 1, True)
'WScript.echo schedule
If return = 0 Then
WScript.Echo "the task was successfully created"
Else
WScript.Echo "there were problems creating the task"
End If
Else
WScript.Echo "Job already exists"
'delete previous task
fso.DeleteFile (sysroot & JobName),True
'rerun task creation
chkSched()
End If
End Sub
Function setFileDate()
theyear = DatePart("yyyy", Date())
themo = DatePart("m", Date())
'check for length, pad zero if needed
if len(themo) < 2 then themo = "0" & themo end if
theday = DatePart("d", Date())
'check for length, pad zero if needed
if len(theday) < 2 then theday = "0" & theday
setFileDate = themo & "/" & theday & "/" & theyear
End Function 'setFileDate
Answered 03/25/2009 by: neel.login
Senior Yellow Belt

Please log in to comment
0
The article to which I linked states that WMI isn't able to access tasks created by AT or SCHTASKS so your script will need to be re-worked to use the WMI class to create the task. Then you need to add the code to handle the task deletion.
Answered 03/25/2009 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity