Schedule Task search & delete

Ok I tried that too & below is the result -

Command failed (Relevance substitution failed) 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 = “%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22 BESClient auto”)))}

This was the action -

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 = “%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22 BESClient auto”)))}
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 = “%22C:\Windows\system32\cmd.exe%22 /c net start BESClient”)))}
delete RemoveTasks.cmd
move __appendfile RemoveTasks.cmd
waithidden cmd.exe /C RemoveTasks.cmd

I tried your suggestion too but still throwing exit code 1 -
Command succeeded (Exit Code=1) waithidden schtasks.exe /delete /TN \At2\At4\At6\At8 /F

The answer is definitely what @jasonwalker is saying – take that relevance and try it in fixlet debugger on the client you are targeting and see where it’s failing.

Should be
names of scheduled tasks

1 Like

Thanks Jason ! that worked & solve the error, now its getting executed without any error but still schedule task are not getting deleted, I tried running it in fixlet debugger on test machine but nothing new.

You can find removetasks.cmd in the __BESData\__FixletDebugger of the client running fixlet debugger.

Can you share the contents of that file?

Yes, content is there in action, we are creating it on the fly :slight_smile:

Yes, I’m asking for the contents of removetasks.cmd. Can you grab it off the machine after it’s been created using Fixlet Debugger so we can see what might be happening?

ohhhh might I got it problem is with removetask.cmd this file is getting created blank buy why is it so.

OK, even these files are creating blank, I tried to manually put the same content which we are trying to put using appendfile, its still failling & no task getting deleted.

Run the relevance in fixlet debugger on the machine and make sure it’s outputting what you expect. Appendfile will only write what the relevance returns so if the relevance isn’t returning anything youll get a blank file.

1 Like

Getting the results while putting relevance in this way -

Q: (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 = “C:\Windows\system32\cmd.exe”)))
A: At2
A: At4
A: At6
A: At8
T: 82.325 ms

Q: (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 = “C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe”)))
A: At1
A: At3
A: At5
A: At7
T: 85.773 ms

but using above relevance task’s action is not complete & when I am using original relevance I am getting nothing -

Q: (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 = “%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22 BESClient auto”)))
T: 82.380 ms

Q: (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 = “%22C:\Windows\system32\cmd.exe%22 /c net start BESClient”)))
T: 101.110 ms

Any suggestion how to write full action in relevance to check -

  1. C:\Windows\system32\cmd.exe /c net start BESClient
  2. C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe BESClient auto

So lets back up a second.

When we are working with relevance we have to be very precise. We need to work with exactly what is in your fixlet, it doesn’t matter what those relevance queries return if you aren’t using those relevance queries in your fixlet.

We want a known working base relevance (get the names of the scheduled tasks), we want to build each piece one at a time making sure it works, and then we want to put it into the fixlet.

Start with the relevance that works, and add on pieces until you get to what you’re using in your fixlet. Share the results of each step with what the answer is in fixlet debugger and we can see at what step it stops working.

I’d recommend starting with the one you know works:

(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 = "C:\Windows\system32\cmd.exe")))

add the ("schtasks.exe /delete /TN " & it & " /F") piece to it, and then add the concatenation "%0d%0a" of piece to it. Make sure each part works in fixlet debugger before adding the next and capture the results and share them here. Once we find the part that isn’t working we can go from there.

Thanks !

As guided I did performed 4 steps where two steps showing results but after making changes in action content its showing nothing or seems not working, below is the results.

Q: (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 = “C:\Windows\system32\cmd.exe”)))
A: At2
A: At4
A: At6
A: At8
T: 90.433 ms

Q: concatenation “%0d%0a” of (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 = “C:\Windows\system32\cmd.exe”)))
A: At2%0d%0aAt4%0d%0aAt6%0d%0aAt8
T: 98.028 ms

Q: concatenation “%0d%0a” of (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 = “C:\Windows\system32\cmd.exe /c net start BESClient”)))
A:
T: 96.424 ms

Not working ones are below -

Q: concatenation “%0d%0a” of (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 = “C:\Windows\system32\cmd.exe /c net start BESClient”)))
A:
T: 96.424 ms

Q: concatenation “%0d%0a” of (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 = “%22C:\Windows\system32\cmd.exe%22 /c net start BESClient”)))
A:
T: 87.106 ms

Alright, I think you’re getting confused about the approach here.

We have to do a couple things:

  1. Get a list of our Scheduled Tasks
  2. Wrap each scheduled task in our schtasks.exe command line
  3. Put carriage returns between each schtasks.exe line so they run as separate commands.
  4. Make it into a fixlet

We can never proceed to the next step until the previous step is working. If our original relevance for getting the scheduled tasks doesn’t work then our fixlet is doomed to fail.

I have a scheduled task called AT4 that should match yours.

Get a list of Scheduled Tasks

This relevance (using the scheduled task inspectors) should appropriately pull each of your scheduled tasks:

Q: names of scheduled tasks whose ((path of it = "%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))
A: AT4
A: AT5

Wrap each scheduled task with schtasks.exe (from Jason)

To do this we will add ("schtasks.exe /delete /TN " & it & " /F") of ... to our relevance. The important part here is the & it &. For each of our scheduled tasks, it will put the name of the task where that is is and generate our command line.

Q: ("schtasks.exe /delete /TN " & it & " /F") of names of scheduled tasks whose ((path of it = "%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))
A: schtasks.exe /delete /TN AT4 /F
A: schtasks.exe /delete /TN AT5 /F

Now, if we take this relevance and put it into an appendfile in actionscript what happens?

ActionScript:

appendfile {("schtasks.exe /delete /TN " & it & " /F") of names of scheduled tasks whose ((path of it = "%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))}

We get this:

Contents of __appendfile

schtasks.exe /delete /TN AT4 /Fschtasks.exe /delete /TN AT5 /F

Put carriage returns between each schtasks.exe line

Next we need to put some new lines between our schtasks.exe so they run as separate commands. To do this we use the concatenation "%0d%0a" of ... relevance that Jason provided:

Q: concatenation "%0d%0a" of ("schtasks.exe /delete /TN " & it & " /F") of names of scheduled tasks whose ((path of it = "%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))
A: schtasks.exe /delete /TN AT4 /F%0d%0aschtasks.exe /delete /TN AT5 /F

Now this might not look right yet but if we make it into actionscript:

Actionscript:
appendfile {concatenation "%0d%0a" of ("schtasks.exe /delete /TN " & it & " /F") of names of scheduled tasks whose ((path of it = "%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))}

Contents of __appendfile:

schtasks.exe /delete /TN AT4 /F
schtasks.exe /delete /TN AT5 /F

Make it into a fixlet

Actionscript:

delete __appendfile

appendfile {concatenation "%0d%0a" of ("schtasks.exe /delete /TN " & it & " /F") of names of scheduled tasks whose ((path of it = "%22C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe%22" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))}

delete run.bat
move __appendfile run.bat

wait run.bat

I would make the removal of the other scheduled tasks, the cmd.exe /c net start besclient into another fixlet and develop/test them separately.

3 Likes

@steini44

I want to create a scheduled task in bigfix, could you please share the action script ?

Hi,

This post is regarding the original poster’s issue searching and removing scheduled tasks. It appears your question is related to scheduled tasks but not this post – can you post a new topic on the forum home page with your question?

Bill

2 Likes

1st of all I would like to thank you so much, I never thought this would be possible, after all this today I was able to remove them with your & @JasonWalker’s shared relevance & action script.

Above one somehow still didnt worked but I changed it this way & this worked, however idea was correct.

Q: names of scheduled tasks whose ((path of it = "C:\Program Files (x86)\BigFix Enterprise\BES Client\__BESData\BES Support\changeservicestartmode.exe" and argument string of it = "BESClient auto") of (action of definition of it as exec task action))
A: At1
A: At3
A: At5
A: At7
T: 271.547 ms
1 Like

That’s great news!

For your reference the %22 translates into a double quote. So in my test scheduled task I had the path quoted so in task scheduler it looked exactly like this "C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe"

My guess is yours is not quoted, it looks like this C:\Program Files (x86)\BigFix Enterprise\BES Client__BESData\BES Support\changeservicestartmode.exe

That would explain why my %22 didn’t work but yours did :slight_smile:

Thanks for hanging in there!
Bill

2 Likes

Great work, guys! This is a good example of what keeps the BigFix forum awesome.