Link to home
Start Free TrialLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

Need to restart the XP Pro System

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
Avatar of redcelltech
redcelltech
Flag of United States of America image

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

Avatar of curiouswebster

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of zveljkovic
zveljkovic
Flag of Serbia 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