?
Solved

Scheduled reboot

Posted on 2012-03-30
13
Medium Priority
?
278 Views
Last Modified: 2012-04-04
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?
0
Comment
Question by:YZlat
[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
  • 6
  • 6
13 Comments
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1500 total points
ID: 37788890
System.Diagnostics.Process.Start("ShutDown", "/r ")

A message box should pop up to warn the user a scheduled shutdown is taking place.  You can use the /t switch to specify how long before the shutdown takes place.
0
 
LVL 6

Expert Comment

by:-tjs
ID: 37788978
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.
0
 
LVL 35

Author Comment

by:YZlat
ID: 37788994
paulmacd, can you give me some examples?

-tjs, I need examples using .NET
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 1500 total points
ID: 37789029
System.Diagnostics.Process.Start("ShutDown", "/r /t 300 ")

...where the /t 300 tells the system to countdown for 5 minutes (300 seconds) before performing the reboot.
0
 
LVL 35

Author Comment

by:YZlat
ID: 37789041
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?
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1500 total points
ID: 37789159
Ah, that's different altogether.

Try something like this (from http://stackoverflow.com/questions/206323/how-to-execute-command-line-in-c-get-std-out-results):
//Create process
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();  

//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = strCommand;  

//strCommandParameters are parameters to pass to program pProcess.StartInfo.Arguments = strCommandParameters;  pProcess.StartInfo.UseShellExecute = false;  

//Set output of program to be written to process output stream pProcess.StartInfo.RedirectStandardOutput = true;    

//Optional
pProcess.StartInfo.WorkingDirectory = strWorkingDirectory;  

//Start the process
pProcess.Start();  

//Get program output
string strOutput = pProcess.StandardOutput.ReadToEnd();  

//Wait for process to finish
pProcess.WaitForExit();


... and use the AT command to run the SHUTDOWN /R command
(info on AT command: http://support.microsoft.com/kb/313565)
Your AT command will look something like this:
at [time] /next:[dayofmonth] cmd /c "shutdown /r"

Note that your strCommand in the code sample above will be "AT" and strCommandParameters will be everything else.  

As a matter of full disclosure, this isn't something I've tested myself.
0
 
LVL 35

Author Comment

by:YZlat
ID: 37795863
paulmacd, I have searched everywhere but cannot find AT command or switch anywhere
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1500 total points
ID: 37795923
0
 
LVL 35

Author Comment

by:YZlat
ID: 37801057
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?
0
 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 1500 total points
ID: 37801147
Not as such.  

You could ask the user before you start the shutdown, or you could offer the user the opportunity to cancel the shutdown (shutdown /a).
0
 
LVL 35

Author Comment

by:YZlat
ID: 37802380
Thank you. I am gonna give that a try
0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 37805867
thanks for your help, you pointed me in the right direction
0
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 37805884
Very happy to help.
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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