JSI Tip 7595. How do I script a Scheduled Tasks password reset?

Using the Schtasks.exe command-line tool, I have scripted SchTasksFix.bat, to reset the password on all Scheduled Tasks on a local or remote computer.

NOTE: See Windows XP contains a full featured command-line scheduler.

NOTE: See How do I use Schtasks.exe to schedule tasks in Windows Server 2003?

NOTE: See Can I use the Windows XP command line scheduler in Windows 2000?

The syntax for using SchTasksFix.bat is:

SchTasksFix UserPwdFile \[ComputerName\]


UserPwdFile   contains every possible user name that you may have used in the Run as box,
              with its'  associated password, using the following formats:


              NOTE: No quote (") marks are required, or allowed.

CompterName   is an optional NetBIOS name of a remote computer.
SchTasksFix.bat sets ERRORLEVEL as follows:

0 - No errors were encountered.

1 - Improper syntax, no parameters specified.

2 - UserPwdFile NOT found.

3 - ComputerName NOT reachable.

4 - One or more Scheduled Tasks Run as a UserName not specified in the UserPwdFile file.

SchTasksFix.bat contains:

@echo off
if \{%1\}

\{\} @echo Syntax: SchtasksFix UserPwdFile \[ComputerName\]&exit /b 1 if not exist %1 @echo UserPwdFile %1 NOT found. SchtasksFix UserPwdFile \[ComputerName\]&exit /b 2 setlocal set ec=0 set file=%1 set computer=%computername% if not \{%2\}

\{\} set computer=%2 set computer=%computer:\=% set work="\\%computer:"=%\c$" if not exist %work% @echo Computer %computer% NOT found. SchtasksFix UserPwdFile \[ComputerName\]&exit /b 3 for /f "Tokens=*" %%t in ('Schtasks.exe /query /S %computer% /V /FO LIST') do set taskline=%%t&call :change endlocal&exit /b %ec% :change if /i "%taskline:~0,9%" EQU "TaskName:" set task=%taskline:~38% if /i "%taskline:~0,12%" NEQ "Run As User:" goto :EOF set User=%taskline:~38% set pwd= for /f "Tokens=1* Delims==" %%p in ('findstr /B /L /I /C:"%User%" %file%') do set pwd=%%q if not defined pwd @echo %User% password not found in %file%&set ec=4&goto :EOF schtasks.exe /change /S %computer% /tn "%task%" /RU "%User%" /RP "%pwd%" If ERRORLEVEL 1 set ec=5&@echo Reset for task "%task%", User "%User%" failed.
NOTE: Schtasks.exe displays a console message for each Scheduled Task:

SUCCESS: The parameters of scheduled task "Task Name" have been changed.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.