If i were tto implement somthing like this :idea:

cmd \k shutdown.exe -r

on a button click would that saftley restart y comp. from that app. if not how would i do this :?:

google is letting me down :(

try this:

using System.Diagnostics;

ProcessStartInfo startinfo = new ProcessStartInfo("shutdown.exe","-r");
Process.Start(startinfo);

try this:

using System.Diagnostics;

ProcessStartInfo startinfo = new ProcessStartInfo("shutdown.exe","-r");
Process.Start(startinfo);

hmmm the r stands for restart so is l logoff?

-i                      Display GUI interface, must be the first option
        -l                      Log off (cannot be used with -m option)
        -s                      Shutdown the computer
        -r                      Shutdown and restart the computer
        -a                      Abort a system shutdown
        -m \\computername       Remote computer to shutdown/restart/abort
        -t xx                   Set timeout for shutdown to xx seconds
        -c "comment"            Shutdown comment (maximum of 127 characters)
        -f                      Forces running applications to close without war
ning
        -d [u][p]:xx:yy         The reason code for the shutdown
                                u is the user code
                                p is a planned shutdown code
                                xx is the major reason code (positive integer le
ss than 256)
                                yy is the minor reason code (positive integer le
ss than 65536)

-l would be logoff

Tahnk you and is thissafe for the computer?

yeah its safe, its no different then going to cmd and using it

yeah its safe, its no different then going to cmd and using it

lol ok thanks so i guess its safe there

-i                      Display GUI interface, must be the first option
        -l                      Log off (cannot be used with -m option)
        -s                      Shutdown the computer
        -r                      Shutdown and restart the computer
        -a                      Abort a system shutdown
        -m \\computername       Remote computer to shutdown/restart/abort
        -t xx                   Set timeout for shutdown to xx seconds
        -c "comment"            Shutdown comment (maximum of 127 characters)
        -f                      Forces running applications to close without war
ning
        -d [u][p]:xx:yy         The reason code for the shutdown
                                u is the user code
                                p is a planned shutdown code
                                xx is the major reason code (positive integer le
ss than 256)
                                yy is the minor reason code (positive integer le
ss than 65536)

-l would be logoff

I had an idea for a program and saw this. Thank you for the advice, it really helped; however, I am not sure how to implement it all...

... when using the following commands, what is the correct way to input it?

following the example code given earlier, I typed:
ProcessStartInfo startInfo = new ProcessStartInfo("shutdown.exe", "-m \\COMPUTERNAME");

upon clicking the button this code was written for, nothing happened on the computer I was trying to shut down, though (unfortunately) my computer restarted after approximately 30 seconds. I don't think I input it correctly, or I was attempting to do something -m wasn't meant to do?

Also, when I typed "-t 10" (wanting the computer to shut down 10 seconds after the button was clicked, nothing happened.

Wat am I doing wrong?
Thanks for the help
j4nu5

But why you use shutdown.exe?

There are API functions: ExitWindows, ExitWindowsEx, InitiateSystemShutdown, InitiateSystemShutdownEx. Try this.

I was trying to do it with the shutdown.exe because I did not know about this way.

For the API functions do I just need to be

using System;

or is there something else I would need to "use" in order for it to work.

thanks

Yes - API is the perfect way of doing it. Spawning a command prompt etc. eventually under Vista (UAC) will create a lot of undesirable results.

Look up DllImport attibute for calling APIs in .NET.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.