Friday, February 24, 2006

Using Shutdown.exe

Q: How can I remotely shutdown a machine in a workgroup?

A: Use the Shutdown.exe command with the –m switch. This command is found in the Windows System directory (i.e. C:\Windows\system32 for Win XP), and will allow you to specify a remote computer name to shutdown. See the following for more info

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 less than 256)
yy is the minor reason code (positive integer less than 65536)

This can be executed from a script or a .Net program.

2 comments:

  1. A couple of caveats on this utility:
    1) You must have the right to shut down the remote computer. At minimum, you must have "Shut down the system" user right.
    2) If the remote system is Windows Server 2003, you must have local administrator rights, use the updated shutdown.exe utility that comes with Windows Server 2003, and enter the "/d" option to enter a shutdown reason code.
    3) This utility "may not" (likely will not) work if a user has locked the current console session on the remote computer.
    4) You can also use System.Runtime.InteropServices and call the ExitWindowsEx function, but that will require setting process token permissions and all sorts of other gunky stuff. Look here: http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=6D5BA0F2-77C8-43CE-A0EC-4A9A89D47FAD

    ReplyDelete