Solved

Need a script (windows 7) to schedule a task

Posted on 2014-09-18
6
148 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 28

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

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 28

Expert Comment

by:becraig
ID: 40331783
Happy to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

22 Experts available now in Live!

Get 1:1 Help Now