Click here to Skip to main content
13,090,299 members (91,398 online)
Click here to Skip to main content
Add your own
alternative version


30 bookmarked
Posted 29 Nov 2006

Shutting Down Your Computer

, 29 Nov 2006
Rate this:
Please Sign up or sign in to vote.
This article will show you a simple way to shutdown, restart, or log off your computer.

Sample Image - Shutdown Computer.jpg


Some programs have a "Reboot your computer for changes to take affect" option after installing updates or changing settings. But how do they reboot your computer? It's very simple. You just call "C:\WINDOWS\System32\ShutDown.exe", which is the same as typing "Shutdown" in the Command Prompt (in Windows XP).


Here is a list of all the arguments used:

  • -i: Display the GUI interface
  • -l: Log off
  • -s: Shutdown the computer
  • -r: Shutdown and restart the computer
  • -a: Abort a system shutdown
  • -f: Forces all windows to close
  • -t xx: Set timeout for shutdown to xx seconds

Starting the Shutdown Process

Start the shutdown process by calling ShutDown, like so:

System.Diagnostics.Process.Start("ShutDown", "/s") 'Shutdown

And to abort the shutdown:

System.Diagnostics.Process.Start("ShutDown", "/a")

This is very important to have when testing your app, because otherwise there is no way to stop the shutdown process.

Shutdown Dialog

After you start the shutdown/restart process, a dialog will appear with a warning to close all running processes before the computer shuts down.

Shutdown Dialog

This screen is required to give users a warning that their computer is about to be shutdown so they can close all running processes, but this can be disabled by using the -f argument, which forces all windows to close.

GUI Interface

This is the GUI interface which allows advanced customization of the shutdown process. For example, you can set which computers to shutdown, the process for each computer (shutdown, restart etc.), set a shutdown timer, and much more.

GUI Interface


Overall, I don't really like the shutdown process, it's not very customizable. I think that would make a good addition to the .NET Framework, which would allow more control. But if you just want a simple function to restart your computer, this is perfect.

Also, using this shutdown example will not work in Windows ME or below, only in Windows XP. And, administrators can block unauthorized users from shutting down the computer, which can cause problems.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 2 Pin
Ajizen13-Oct-09 8:14
memberAjizen13-Oct-09 8:14 
Questionhow can i use anther programm in my project? Pin
shereenbasher8-Aug-07 11:58
membershereenbasher8-Aug-07 11:58 
GeneralReverse Method... Pin
shein4-Feb-07 17:11
membershein4-Feb-07 17:11 
GeneralRe: Reverse Method... Pin
MatrixCoder5-Feb-07 4:49
memberMatrixCoder5-Feb-07 4:49 
GeneralNot true! Pin
Galatei30-Nov-06 3:38
memberGalatei30-Nov-06 3:38 
GeneralRe: Not true! Pin
MatrixCoder4-Apr-07 17:56
memberMatrixCoder4-Apr-07 17:56 
GeneralDoesn't work on some PCs Pin
coshishonour30-Nov-06 1:51
membercoshishonour30-Nov-06 1:51 
GeneralRe: Doesn't work on some PCs Pin
Christian Klauser30-Nov-06 2:24
memberChristian Klauser30-Nov-06 2:24 
GeneralRe: Doesn't work on some PCs Pin
Lito30-Nov-06 3:11
memberLito30-Nov-06 3:11 
GeneralRe: Doesn't work on some PCs Pin
coshishonour30-Nov-06 5:07
membercoshishonour30-Nov-06 5:07 
AnswerRe: Doesn't work on some PCs Pin
tkrafael_net30-Nov-06 6:08
membertkrafael_net30-Nov-06 6:08 
AnswerRe: Doesn't work on some PCs Pin
coshishonour6-Dec-06 23:11
membercoshishonour6-Dec-06 23:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 30 Nov 2006
Article Copyright 2006 by MatrixCoder
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid