3

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?

1 Answer 1

6

Use schtasks.

schtasks /create /tn "Shutdown" /tr "shutdown -s -f -t 0" /sc daily /st 23:00:00
7
  • 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? Sep 6, 2011 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.) Sep 6, 2011 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 ;]) Sep 6, 2011 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. Sep 6, 2011 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? ;) Sep 6, 2011 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .