Link to home
Start Free TrialLog in
Avatar of Reyesrj
ReyesrjFlag for Guam

asked on

Need a script (windows 7) to schedule a task

Hi All,

I wrote a script and it works:
schtasks /Create /TN "Shutdown 11pm" /TR C:\Windows\System32\nw-SC\Nsd.cmd /SC DAILY /ST 23:01 /RU admin /RP rogue

The task gets created but will not run.  I'm thinking that the "/RU admin" should read /RU [hostname]/admin.  I tried,
/RU %hostname%\admin.  The task will not get created.

Thanks in advance
Avatar of ktaczala
ktaczala
Flag of United States of America image

try this from an elevated command prompt:

at 23:01 /every: M. T, W, Th, F, Sa, Su C:\Windows\System32\nw-SC\Nsd.cmd

This will run with admin rights even when logged off.
schtasks /Create /TN "Shutdown 11pm" /TR C:\Windows\System32\nw-SC\Nsd.cmd /SC DAILY /ST 23:01 /RU admin /RP rogue /RL

you can check the actual user name by just running:

whoami  from a command prompt window, then insert that value for the username and try again.
Avatar of Reyesrj

ASKER

Thanks becraig,
We clone workstations and I would like to create a task to run the script one time after image is completed.  Is there a way to create one script that will use the hostname before admin?  I'm trying to create one script and not need to make adjustments  to it for every workstation.
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

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
Avatar of Reyesrj

ASKER

Thanks becraig!
Woked perfect!!!

BTW, I used CMD.
Happy to help.