Sunday, May 30, 2010

SchTasks for backups with examples

It's easy to find the switches here but not so easy to find working examples.

Following up on the previous post(s) to schedule a tasks use this example:
schtasks /create /tn "Check server Mon-Fri at 8am" /tr c:\scripts\checkserver.bat /sc weekly /d Mon,Tue,Wed,Thu,Fri /st 8:00:00 /ru %computername%\%username% /rp %pass%

The computername and username are set by the system, you will need to specify the password:
SET pass=mySecurePass

So your script can look like:
SchTasks.bat
@echo off
SET pass=mySecurePass

echo Adding Check Server scheduled task...
schtasks /create /tn "Check server Mon-Fri at 8am" /tr c:\scripts\checkserver.bat /sc weekly /d Mon,Tue,Wed,Thu,Fri /st 8:00:00 /ru %computername%\%username% /rp %pass%

echo.
echo done..
pause

NOTE: if you are using a domain instead of workgroup you will need to specify that instead of %computername%.

No comments: