Solved

Need to restart the XP Pro System

Posted on 2008-06-15
3
218 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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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