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.
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)
Please log in to answer
Posted by:
spartacus
18 years ago
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
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.
so that the conversation will remain readable.