Code: Select all
schtasks /query > app
findstr /B /I "AppleSoftwareUpdate" app > nul
if %errorlevel%==0 goto delete
goto exit
:delete
schtasks /DELETE /TN "AppleSoftwareUpdate" /F > nul
:exit
exit
Moderator: DosItHelp
Code: Select all
schtasks /query > app
findstr /B /I "AppleSoftwareUpdate" app > nul
if %errorlevel%==0 goto delete
goto exit
:delete
schtasks /DELETE /TN "AppleSoftwareUpdate" /F > nul
:exit
exit
Code: Select all
H:\>schtasks /query /tn xdbstart >nul 2>&1
H:\>echo %errorlevel%
0
H:\>schtasks /query /tn xdbstar >nul 2>&1
H:\>echo %errorlevel%
1
It sounds like your if test is not working correctly. Check the errorlevels for findstr. It may work the opposite of other commands.jason76 wrote:I am trying to delete a scheduled task on Windows 7 computers if it exists. I found this online but can't get it to work for me. I need the script to delete the task if it exists and if it does not exist to exit the batch file without trying to delete it. Right now it is trying to delete it whether or exists or not so when it is does not exist it gives a "ERROR: The system cannot find the file specified" which is messing up another process I have going on.Code: Select all
schtasks /query > app
findstr /B /I "AppleSoftwareUpdate" app > nul
if %errorlevel%==0 goto delete
goto exit
:delete
schtasks /DELETE /TN "AppleSoftwareUpdate" /F > nul
:exit
exit
Code: Select all
schtasks /query | findstr /B /I "AppleSoftwareUpdate" >nul && schtasks /DELETE /TN "AppleSoftwareUpdate" /F > nul