A Digital Age Deserves A Digital Leader

.NET Shutdown / Reboot Command

.NET Shutdown / Reboot Command

Postby jonnywright » Tue Sep 09, 2003 1:25 pm

Does anyone know the command to reboot or shutdown a machine when programming with VB.net or C#.net? Or even just the actual application (if it is one :confused ) that shuts down / reboots your machine?
Thanks in advance!

-Jonny
Banned
User avatar
Posts: 53
Joined: Thu Aug 14, 2003 10:25 pm
Location: Leicester UK

Postby Weaver » Tue Sep 09, 2003 10:26 pm

I am not much of a programmer in a Windows environment, but the dll you are going to want to call is rundll32.dll, pass a few parameters to rundll32.dll and you can shutdown, reboot, logout, etc . There are a couple similar ways of doing it.

http://listas.rcp.net.pe/pipermail/wind ... 01652.html

There's a great link, will do a much better job explaining it than I can.

-Weaver
Public Keys

The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
PROfessional Member
User avatar
Posts: 1967
Joined: Wed Jun 19, 2002 12:05 am
Location: /home/weaver/

Postby h_bhanu » Thu Mar 04, 2004 3:09 am

If you're running Windows XP you can do this (Note: You need to have admin-privelages to do this.):

From DOS Console
Code: Select all

Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "c
omment"] [-d up:xx:yy]

        No args                 Display this message (same as -?)
        -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)


So if you wanted to restart (instantly) the command-line equiv. would be:

shutdown -r -t 0

Also, if your computer decides it wants to shutdown (like if SVCHost.exe was terminated, etc) you can use the -a switch to continue working.

I know that in C/C++ you can use: "system()", and whatever was in the parenthesis would be executed @ command-line...but I'm not sure if this holds true for C#... =/

Hope that helped =)

-Hari
PRO Level 2
User avatar
Posts: 12
Joined: Wed Mar 03, 2004 6:58 am
Location: Clemson, SC

Postby dynamic_scripter » Thu Mar 04, 2004 5:41 pm

Image Image Image
PRO New Member
User avatar
Posts: 5
Joined: Wed Mar 03, 2004 10:59 pm
Location: UK

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 5 guests