Ok so this is returning the true/false values correctly, right? Youâd make a Fixlet and include this in the Relevance:
(exists scheduled tasks whose (exists (node values of child nodes of xpaths ("xmlns:t='http://schemas.microsoft.com/windows/2004/02/mit/task'", "/t:Task/t:Actions/t:Exec/t:Command") of xml document of xml of it) whose (it = "the command I'm looking for")))
That should make the fixlet Relevant for the systems where the task exists (youâd also want to include normal targetting relevance like windows of operating system
for efficiency to prevent this from trying to evaluate on Linux hosts, etc.)
For the Action Script, you need to build the commands to delete the Scheduled Task. For that you need to retrieve the Task Names matching this condition:
(names of scheduled tasks whose (exists (node values of child nodes of xpaths ("xmlns:t='http://schemas.microsoft.com/windows/2004/02/mit/task'", "/t:Task/t:Actions/t:Exec/t:Command") of xml document of xml of it) whose (it = "the command I'm looking for")))
If you were certain that there is only one matching scheduled task, you could have a one-liner in the Action Script:
waithidden schtasks.exe /delete /TN {(names scheduled tasks whose (exists (node values of child nodes of xpaths ("xmlns:t='http://schemas.microsoft.com/windows/2004/02/mit/task'", "/t:Task/t:Actions/t:Exec/t:Command") of xml document of xml of it) whose (it = "the command I'm looking for")))} /F
However, thereâs a chance that there is more than one Scheduled Task on a system matching the condition (for example if the task was created twice, you may have an âAT1â, âAT2â, âAT3â, etc. all doing the same function). In that case, you need to loop through all of the matching tasks, building a batch file to delete each of them. Action Script doesnât have a loop operator, but it does have a way to iterate through the results by building a âconcatenationâ. In this example, â%0d%0aâ represents the Carriage Return / Line Feed pair of characters that mark the end of a line, so this will build a batch file, with one âschtasksâ command on each line
delete __appendfile
appendfile {concatenation "%0d%0a" of ("schtasks.exe /delete /TN " & it & " /F") of (names scheduled tasks whose (exists (node values of child nodes of xpaths ("xmlns:t='http://schemas.microsoft.com/windows/2004/02/mit/task'", "/t:Task/t:Actions/t:Exec/t:Command") of xml document of xml of it) whose (it = "the command I'm looking for")))}
delete RemoveTasks.cmd
move __appendfile RemoveTasks.cmd
waithidden cmd.exe /C RemoveTasks.cmd