Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to restart the XP Pro System

Posted on 2008-06-15
3
Medium Priority
?
228 Views
Last Modified: 2013-12-17
I am writing the code to shut down my program at midnight, well after the store's closed.  But I need Windows to restart shortly thereafter.

Is there an easy way that my C# program can restart Windows?  But I need it to start [shutting down] only after my program is exited.

thanks,
newbieweb
0
Comment
Question by:newbieweb
3 Comments
 
LVL 4

Expert Comment

by:redcelltech
ID: 21790117
Output to a command prompt:

shutdown /r /f /t 0

of

Shutdown /s /f /t 0

Shutdown is obvious

/r is reboot, /s is shutdown

/f is force either option

/t is time: 0


Attached is a code example I have seen online


using System;
using System.Security;
using System.Diagnostics;
 
public class RunAs{
    public static void Main(string[] args) {
        try {
            Console.Write(@"User Name [domain\user] : ");
            string[] userInfo = (Console.ReadLine()).Split('\\'); 
            SecureString secPass = ReadPassword();  
           Process.Start("cmd",userInfo[1],secPass,userInfo[0]);
 
       }
     catch(Exception e){
         Console.WriteLine("\n"+e.Message);
     }
  }
    public static SecureString ReadPassword()
    {
        SecureString secPass = new SecureString();
        Console.Write("Enter your password : ");
        ConsoleKeyInfo key = Console.ReadKey(true);
        while(key.KeyChar != '\r')
        {    
            secPass.AppendChar(key.KeyChar);
            key = Console.ReadKey(true);
        }
         return secPass;
    } 
}

Open in new window

0
 

Author Comment

by:newbieweb
ID: 21790130
Thanks.  But I'm a bit confused by the code for the password.

In my case, I do not have a log on password.  Would you mind simplifying the code to include no password?

thanks,
newbieweb
0
 
LVL 4

Accepted Solution

by:
zveljkovic earned 2000 total points
ID: 21790192
                 System.Diagnostics.Process p = new System.Diagnostics.Process();
                  p.StartInfo.UseShellExecute = true;
                  p.StartInfo.FileName = "shutdown.exe";
                  p.StartInfo.Arguments = "/s /t 300";

                  p.Start();

This works in Vista and 99% in xp.
Hope that helps,
Zlax
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 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