Solved

Need a script (windows 7) to schedule a task

Posted on 2014-09-18
6
150 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

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.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.

809 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