Solved

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

Posted on 2009-06-30
5
367 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Way to decrease size of apk file 9 87
batch file problem 5 67
Perl script to process a .csv file 18 44
creating a random password in batch 4 25
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

830 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