A Script to create a a Scheduled Task that runs under the SYSTEM account

By | September 23, 2016
Share
echo start /w "" notepad.exe > "%WinDir%\Temp\temp.bat"
echo del /f/q "%%WinDir%%\Temp\temp.bat" >> "%WinDir%\Temp\temp.bat"

schtasks /create /ru "NT AUTHORITY\SYSTEM" /tn "sysrun" /tr "cmd.exe /c ""%WinDir%\Temp\temp.bat""" /f /sc "ONIDLE" /i "999"
schtasks /run /tn "sysrun" /i

:loop
for /f "tokens=2 delims=: " %%f in ('schtasks /query /tn "sysrun" /fo list ^| find "Status:"' ) do (
    if "%%f"=="Running" (
        timeout /T 1 /NOBREAK > nul
        goto loop
    )
)
schtasks /delete /tn "sysrun" /f

Use echos to make your temp.bat and then run it under the System account using a scheduled task.

I set the task to run  ONIDLE with a timer of 999, which should never occur.

/BG

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.