Solved

Scheduled task delete code. Need a condition to match before deletion.

Posted on 2009-06-30
5
363 Views
Last Modified: 2012-05-07
Hi,

Scheduled task delete code. Need a condition to match before deletion.
If the Run of the schedule matches this
"C:\Program Files\Sophos\Sophos Anti-Virus\BackgroundScanClient.exe"
Then delete
Except the scan name as 'infected scan"
The "Infected scan" will also have the same path. So exclude it as it does now but delete just the scans that may have this path.
"C:\Program Files\Sophos\Sophos Anti-Virus\BackgroundScanClient.exe"
Regards
Sharath
@echo off

set rpt=c:\TaskReport.txt

set TaskNOTToDelete=Infected scan

for /f %%a in (c:\computers16.txt) do call :process %%a

goto :eof

 

:process

set pc=%1

ping %pc% -n 1 >nul

if errorlevel 1 (

  echo Could not connect to %pc%

  goto :eof

)

echo Checking %pc%>>%rpt%

for /f "tokens=1,*" %%s in ('schtasks /query /s \\%pc% /fo list^|find /i "TaskName:"') do (

  echo.     Evaluating %%s %%t>>%rpt%

  if /i "%%t" == "%TaskNOTToDelete%" goto :eof

  echo.     Removing %%t from %pc%>>%rpt%

  schtasks /delete /s \\%pc% /tn "%%t" /f

)

Open in new window

0
Comment
Question by:bsharath
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
t0t0 earned 500 total points
ID: 24750031
My first observation is: Do the spaces either side of the '==' make a difference as in:

      if /i "%%t" == "%TaskNOTToDelete%" goto :eof

Should this be:

      if /i "%%t"=="%TaskNOTToDelete%" goto :eof
0
 
LVL 11

Author Comment

by:bsharath
ID: 24762638
Thank U
Will this delete all that may have just those paths?
0
 
LVL 11

Author Comment

by:bsharath
ID: 24859799
Hi...
Any views on this
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24859984
Will look at the code again when i return to pc later today
0
 
LVL 11

Author Comment

by:bsharath
ID: 24942681
Any views...
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now