Link to home
Start Free TrialLog in
Avatar of mdp2176
mdp2176

asked on

Scripting scheduled tasks with Run As

How does one script the creation of Windows Scheduled Task and set the Run As property of the task at the same time?  I can create a scheduled task easily though vbscript, but can't for the life of me find anything that says how the Run As property can be set through code.  Thanks!
Avatar of matt023
matt023

there is a corresponding executable for the "Run As" property.  It's appropriately called "runas.exe".  However, it will ask you a password which you must some how have your script pass to it.

*******************************************

RUNAS USAGE:

RUNAS [/profile] [/env] [/netonly] /user:<UserName> program

   /profile        if the user's profile needs to be loaded
   /env            to use current environment instead of user's.
   /netonly        use if the credentials specified are for remote access only.
   /user           <UserName> should be in form USER@DOMAIN or DOMAIN\USER
   program         command line for EXE.  See below for examples

Examples:
> runas /profile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""

NOTE:  Enter user's password only when prompted.
NOTE:  USER@DOMAIN is not compatible with /netonly.
ASKER CERTIFIED SOLUTION
Avatar of drazak1
drazak1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial