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   [ - ] Hide 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.
Answer this question or Comment on this question for clarity


yeah, exactly. This is why I use the schtasks.exe utility.
Answered 10/12/2006 by: brenthunter2005
Fifth Degree Brown Belt

Please log in to comment
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

[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 !


Answered 10/12/2006 by: spartacus
Black Belt

Please log in to comment