Solved

Need a script (windows 7) to schedule a task

Posted on 2014-09-18
6
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help Creating PowerShell Script 4 67
PowerShell and cisco ios 3 69
Hta File displays dynamic File names 4 65
How to create a registry Subkey containing the hostname 7 38
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

752 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