Solved

Need to restart the XP Pro System

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now