Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to restart the XP Pro System

Posted on 2008-06-15
3
Medium Priority
?
227 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
[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
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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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