Eventually, all of us who manage computer networks need to reboot multiple computers as part of a maintenance task. The Windows Server 2003 or Windows XP Shutdown command and the Shutdown utility from the Microsoft Windows 2000 Server Resource Kit provide basic functionality but often fall short when dealing with shutdown variations on multiple remote computers. Sysinternals' PsShutdown, one of the tools in Sysinternals' free PsTools utility suite, offers more flexibility and power than the Microsoft Shutdown tools do. Plus, PsShutdown works on Windows NT 4.0 and later, although some options require Win2K or later. (See "Make Remote Shutdowns a Snap," January 2005, InstantDoc ID 44710 for another custom shutdown tool.)
PsShutdown is a command-line tool that works on local and remote systems. You don't need to install software on any remote systems against which you want to run the tool.
Figure 1 shows PsShutdown's syntax, which requires at least one argument specifying the type of shutdown you want to perform. This requirement prevents you from accidentally initiating a shutdown of the local system. Table 1 lists the types of shutdown that the tool supports. As you can see, PsShutdown offers power management—related options in addition to a standard shutdown or reboot. If one of these shutdown options is the only argument you specify, PsShutdown displays the dialog box that Figure 2 shows, then performs the specified operation after a default timeout of 20 seconds.
Shutdown, poweroff, and reboot actions typically give applications a chance to abort a shutdown. For example, if a Microsoft Word document that contains unsaved changes is open on a user's system, Word asks the user whether he or she wants to save the file before Word exits. After a default period of 5 seconds (as specified in the HKEY_CURRENT_USER\CONTROL PANEL\Desktop\HungAppTimeout registry entry), Windows displays a dialog box that offers the user the option to cancel the shutdown or to exit the application and continue the shutdown process. By default, Windows displays this dialog box indefinitely, but you can use PsShutdown's -f switch to force open applications to close even when they contain unsaved data.
When you perform shutdown operations (especially on remote systems), you might want to inform active users of the reason for the shutdown, or perhaps even give them longer than the default time to save their work and log off. You can use PsShutdown's -m switch, followed by a message within quotation marks ("), to add a message at the bottom of the tool's shutdown-notification dialog box. You can use the tool's -t switch to override the default timeout value. You can specify a timeout in seconds or, if you want PsShutdown to perform the operation at a particular time, you can specify that time by using a 24-hour notation. The following sample command will reboot the local system at 10 p.m. and will let users know the reason for the reboot.
complete hotfix installation" -t 22:00 -r
If you're concerned that some users might find the shutdown inconvenient and you want to give them the option of aborting it, use PsShutdown's -c switch to add a Cancel button to the notification dialog box. If you want to cancel an entire shutdown operation that you've already launched but that hasn't yet taken place, you can use the -a switch to abort the operation.
Lock and Logoff
In addition to standard shutdown operations, PsShutdown supports two desktop management—related operations: lock and logoff. You've probably used Group Policy to configure a default idle timeout after which your network's desktop systems lock automatically. However, if you step away from a system without manually locking it and want to ensure—without waiting for the default timeout and without having to physically return to the system—that the system is locked immediately, PsShutdown's -l switch, which immediately locks the specified system, can be helpful.
PsShutdown's logoff option is arguably more useful than its lock option. Some per-user Group Policy and application settings refresh during the logon process. Therefore, you might want to forcibly log off any users that remain logged on after hours. You can use the -o switch to log off system console users.
PsShutdown, like most of the utilities in PsTools, offers several ways for you to identify the computer or computers on which you want it to operate. Run the command without specifying a computer name to have PsShutdown control the local system, or specify a remote system (e.g., comp1) by including a double slash (\\) followed by the computer name, as in the following sample:
You can include multiple computers by using the following syntax:
You can also use an asterisk (*) to target all systems in the current domain:
If you find yourself often needing to perform shutdown operations on a particular group of computers, you can include those system names in a text file, then specify the filename, after the @ symbol, in the PsShutdown command. For example, the command to reboot systems specified in a file named complist.txt would be
In the text file, place the name of each computer, without the leading double slash, on a separate line.
If you try to use PsShutdown to control a computer that's already off, the command might appear to hang for a minute before timing out. This delay, which is the standard Windows timeout for computer connections, can severely lengthen shutdown operations that run against many computers. To shorten the length of time that PsShutdown will attempt to establish a connection before giving up, use the -n switch followed by the desired timeout, specified in seconds.
PsShutdown shares its remote-access capabilities with several other members of the PsTools suite, including PsExec. PsShutdown extracts a Windows service executable to the system that it will control through that system's Admin$ share, starts the service, then sends the service a command that reflects the options you've specified. The service uninstalls after it completes the command. Therefore, you must enable file sharing on any remote computers on which you want to use PsShutdown, and the Admin$ share (which is defined by default) must be defined and accessible through the Common Internet File System (CIFS)/Server Message Block (SMB) and Remote Procedure Call (RPC) TCP/IP ports. The account from which you run PsShutdown must have Administrative group membership on all target systems, or you must use the tool's -u switch to specify an account that has the necessary permissions.
You can download PsShutdown by going to http://www.sysinternals.com and downloading the PsTools suite. For more information about some of the other tools in the suite, see "PsList and PsKill," September 2004, InstantDoc ID 43569, and "PsExec," July 2004, InstantDoc ID 42919.