[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2009-06-30
5
Medium Priority
?
374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
t0t0 earned 2000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

650 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