471,594 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Restart and Shutdown Windows XP - Visual Studio

Greetings to all ....

I have a need to issue a shutdown and/or Restart Windows XP inside my
application. Any help or example code would be appreciated!
--
Phil
Nov 6 '06 #1
5 17241
An easy way is just to call the Shutdown.exe command with the Process.Start
method, passing the desired switches:

Shutdown the computer

Syntax

SHUTDOWN [logoff_option] [/m \\Computer] [options]

logoff_option:
/i Display the GUI (must be the first option) /l Log
off. This cannot be used with /m or /d option /s Shutdown /r
Shutdown and Restart /a Abort a system shutdown.
(only during the time-out period)
/p Turn off the local computer with no time-out or warning
(only with /d) /h Hibernate the local computer (only with
/f ) /e Document the reason for an unexpected shutdown of a
computer

options:
/m \\Computer : A remote computer to shutdown.

/t:xxx : Time until system shutdown in seconds.
The valid range is xxx=0-600 seconds. [default=30]
/c "Msg" : An optional shutdown message [Max 127 chars]

/f : Force running applications to close.
This will not prompt for File-Save in any open
applications.
so will result in a loss of all unsaved data!!!

/d u:xx:yy : List a USER reason code for the shutdown.
/d P:xx:yy : List a PLANNED reason code for the shutdown.
xx Specifies the major reason code (0-255)
yy Specifies the minor reason code (0-65536)

-- Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Phil Tusa" wrote:
Greetings to all ....

I have a need to issue a shutdown and/or Restart Windows XP inside my
application. Any help or example code would be appreciated!
--
Phil
Nov 6 '06 #2
Thanks Peter for your very quick and helpful response!

--
Phil
>An easy way is just to call the Shutdown.exe command with the Process.Start
method, passing the desired switches:

Shutdown the computer

Syntax
Nov 6 '06 #3
Phil Tusa wrote:
Greetings to all ....

I have a need to issue a shutdown and/or Restart Windows XP inside my
application. Any help or example code would be appreciated!
--
Phil
System.Diagnostics.Process.Start("shutdown -f -s -t 0");

I think this should solve your problem
Nov 7 '06 #4
Phil Tusa <pt***@houston.rr.comwrites:
Greetings to all ....

I have a need to issue a shutdown and/or Restart Windows XP inside my
application. Any help or example code would be appreciated!
Besides the solutions mentioned by the others, if you do not want to
spawn another process, have a look at the ExitWindowsEx Win32-API
function[1] (user32.dll).

Best regards,
Martin

[1] http://pinvoke.net/default.aspx/user...WindowsEx.html
Nov 7 '06 #5
Thanks to everyone for your helpful assistance!

--
Phil
>
I have a need to issue a shutdown and/or Restart Windows XP inside my
application. Any help or example code would be appreciated!
Nov 7 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Eric Maino | last post: by
8 posts views Thread by Glenn Lerner | last post: by
3 posts views Thread by Treasure Baloyi | last post: by
reply views Thread by marathoner | last post: by
3 posts views Thread by IdleBrain | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.