Solved

Need a script (windows 7) to schedule a task

Posted on 2014-09-18
6
149 Views
Last Modified: 2014-09-18
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
0
Comment
Question by:Reyesrj
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:ktaczala
ID: 40331721
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.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40331736
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.
0
 

Author Comment

by:Reyesrj
ID: 40331752
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.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40331756
you can do this in powershell

$user = (hostname) + "\admin"
schtasks /Create /TN "Shutdown 11pm" /TR C:\Windows\System32\nw-SC\Nsd.cmd /SC DAILY /ST 23:01 /RU $user /RP password /RL

Open in new window


or bat/cmd
set user=%computername%\admin
schtasks /Create /TN "Shutdown 11pm" /TR C:\Windows\System32\nw-SC\Nsd.cmd /SC DAILY /ST 23:01 /RU %user% /RP password /RL

Open in new window

0
 

Author Closing Comment

by:Reyesrj
ID: 40331778
Thanks becraig!
Woked perfect!!!

BTW, I used CMD.
0
 
LVL 29

Expert Comment

by:becraig
ID: 40331783
Happy to help.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now