Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Scheduled reboot

I am creating a windows service that should run every hour, check database for a reboot date and time and schedule reboot based on the datetime it finds in the database.

I can use Windows scheduler to schedule my windows service and I took care of the data retrieval part. Now I am trying to find the best way to schedule a reboot based on the retrieved value.

Should I use the registry HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer? if so, could you give me an example?

or should i use System.Diagnostics.Process.Start("ShutDown", "/r")?

Also before a reboot I want to show the user a messagebox warning.

Can anyone help?
SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Possible example command line if I wanted to reboot a system called MyServer1 at 11:00pm today:
schtasks /create /tn "Reboot Once" /tr "shutdown /r /f /t 1 /d p:0:0" /sc once /st 23:00 /s MyServer1

This creates a scheduled task on MyServer1 that runs only one time at 11:00pm (/st) and executes the local shutdown command with a 1 second warning and enters a bogus restart reason (/d p:0:0) so the admin isn't prompted to enter a reason when the reboot is done.
Avatar of YZlat

ASKER

paulmacd, can you give me some examples?

-tjs, I need examples using .NET
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

But how can I schedule it at a particular date and time?

For instance if the date retrieved from the database is April 1st 11:00am, how can I schedule the reboot at that time?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

paulmacd, I have searched everywhere but cannot find AT command or switch anywhere
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

paulmacd, I am working on using

System.Diagnostics.Process.Start("ShutDown", "/r /t 300 ")

as you suggested. I get a message displayed that tells me how much time left till shutdown. How can I add a snooze button to it?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

Thank you. I am gonna give that a try
Avatar of YZlat

ASKER

thanks for your help, you pointed me in the right direction
Very happy to help.