/build/static/layout/Breadcrumb_cap_w.png

Scheduled Tasks

Hi,

I can create a Scheduled task using this script include as embedded code into a Wise package

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNewJob = objWMIService.Get("Win32_ScheduledJob")

errJobCreated = objNewJob.Create ("C:\Program Files\SOFT\Test.exe", "********030000.000000+120", True , 1 Or 2 Or 4 Or 8 Or 16, , ,JobId)

The problem is that I can't define the name of the scheduled task, so I can't delete it during Uninstall.

Thanks in advance if you have the solution.

0 Comments   [ + ] Show comments

Answers (2)

Posted by: brenthunter2005 18 years ago
Fifth Degree Brown Belt
0
yeah, exactly. This is why I use the schtasks.exe utility.
Posted by: spartacus 18 years ago
Black Belt
0
For some reason the name of the task appears to be a read only property, as you have discovered.

However, you could use the following script to enumerate all scheduled tasks on the system and kill the task based on the original command line string you supplied for the task - example follows :

[font="Courier New"]Const CommandString = "C:\Program Files\SOFT\Test.exe"

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery("Select * from Win32_ScheduledJob")

For Each objJob in colScheduledJobs
if objJob.Command = CommandString then
err = objJob.Delete
end if
Next

[NB: This script will only enumerate tasks originally created through Win32_ScheduledJob, which may or may not work to your advantage (e.g. if users have manually created scheduled tasks with the same command string, these will not be deleted by the script).]

Hope this is of some use !

Regards,

Spartacus
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ