Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to run a command every night at 11pm on a Windows machine. In order to keep things simple, I'd like to automate the insertion of this command into Windows' event scheduler. I'm looking to do something like this:

insertCommandIntoTaskScheduler.exe --at "11:00pm every night" "shutdown.exe -s -f"

Is this possible, or do I have to use the UI?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Use schtasks.

schtasks /create /tn "Shutdown" /tr "shutdown -s -f -t 0" /sc daily /st 23:00:00
share|improve this answer
    
Weirdest thing happened. 1. This task requires the account owner to be an administrator and 2. this task requires the account owner to have a password, otherwise it will not work. Also, with the above conditions met, this worked on my VirtualBox XP instance here, but a friend's XP machine didn't have schtasks installed for some weird reason. Any ideas? –  Naftuli Tzvi Kay Sep 6 '11 at 0:04
    
The tool might be specific to XP Pro? Also, are you talking about the tool or the shutdown command when you say Admin rights are required? (Not sure about the former, but can fix the latter.) about the former, but can fix the latter.) –  grawity Sep 6 '11 at 4:02
    
I guess the schtasks tool must be an XP Pro thing. Weird. Also, the task itself won't run unless the user is an administrator with a password. (Hopefully it's fixable, then ;]) –  Naftuli Tzvi Kay Sep 6 '11 at 4:18
    
The shutdown tool requires SeRemoteShutdownPrivilege, even for local usage, since it uses remote RPCs. You can grant it to users via secpol.msc (Allow to remotely shut down the machine blah blah) -- but it's a somewhat insecure way. Granting it to INTERACTIVE and BATCH special groups would be the best way. Not sure if the password requirement can be securely avoided. –  grawity Sep 6 '11 at 4:24
    
I'm somewhat new to Windows permissions (as I'm coming from Unix/Linux, and it's a lot more straightforward there). Since this should probably be covered in another question, what should I ask so I can get the right answer? ;) –  Naftuli Tzvi Kay Sep 6 '11 at 15:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.