I’m trying to optimize a simple task: to edit the 4 windows defender tasks in the task manager to all have the same conditions (start only when idle for 10 mins, and end when it’s no longer idle).
It doesn’t give me any errors or anything, however, it doesn’t change the specified tasks (Windows Defender Cache Maintenance; Windows Defender Cleanup; Windows Defender Scheduled Scan; Windows Defender Verification).
I did commit a sin and asked chat GPT for help, but it did more bad than good.
I’m still a beginner to this, on my second semester in System Analysis and Dev, so I’m very sorry in advance.
Bat file with the following: checks if the XML file exists, defines the names of the tasks, for loop to go through every task (also checks if it already exists, replaces it with the new one), says it finished and ends.
XMl with the conditions I need edited.
Bat file: (WinDef task modifier.bat)
@echo off
set "xmlFile=%~dp0tasks.xml"
if not exist "%xmlFile%" (
echo XML file not found: "%xmlFile%"
pause
exit /b 1
)
set "tasks=WindowsDefenderCacheMaintenance WindowsDefenderCleanup WindowsDefenderScheduledScan WindowsDefenderVerification"
for %%T in (%tasks%) do (
:: Check if the task exists
schtasks /query /tn "%%T" >nul 2>&1
if %ERRORLEVEL% == 0 (
:: Delete existing task
echo Deleting task: "%%T"
schtasks /delete /tn "%%T" /f
)
:: Create new task using XML file
echo Creating task: "%%T"
schtasks /create /tn "%%T" /xml "%xmlFile%" /f
)
echo Tasks successfully updated or created.
pause
XML file: (tasks.xml)
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2024-07-22T12:34:56</Date>
<Author>Author</Author>
</RegistrationInfo>
<Triggers>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
</Settings>
<Actions>
<Exec>
<Command>%SystemRoot%System32cmd.exe</Command>
<Arguments>/c "%~dp0WinDef task modifier.bat"</Arguments>
</Exec>
</Actions>
</Task>
What I expected: for it to change said conditions on the tasks when ran as admin.
What I got: no errors, however no edit.
Charlixexx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.