Share via


Shutting Down Computers and Logging Off Users

Microsoft® Windows® 2000 Scripting Guide

For more efficient management of computers in an organization, administrators need the ability to remotely shut down or restart a computer, or to remotely log off a user. The ability to carry out these tasks allows administrators to install software, reconfigure computer settings, remove computers from the network, and perform other tasks without having to manually shut down or restart each computer.

For example, to perform a network upgrade, you might need to shut down all the computers running on a particular network segment. To force a Group Policy upgrade, you need to log users off their computers. If a computer virus is present anywhere in your organization, you might want to shut down as many computers as possible, before the virus has an opportunity to spread. The ability to shut down and restart computers and to log off users programmatically instead of manually can be an enormous time-saver.

Shutdowns, restarts, and logoffs can be performed using the Win32Shutdown method of the Win32_OperatingSystem class along with one of the parameters shown in Table 8.21.

Table 8.21 Win32Shutdown Method Parameters

Value

Description

0

Logoff. Logs the user off the computer. Logging off stops all processes associated with the security context of the process that called the exit function, logs the current user off the system, and displays the logon dialog box.

1

Shutdown. Shuts down the computer to a point where it is safe to turn off the power. (All file buffers are flushed to disk, and all running processes are stopped.) Users see the message, It is now safe to turn off your computer.

During shutdown the system sends a message to each running application. The applications perform any cleanup while processing the message and return True to indicate that they can be terminated.

2

Reboot. Shuts down and then restarts the computer.

4

Forced logoff. Logs the user off the computer immediately and does not notify applications that the logon session is ending. This can result in a loss of data.

5

Forced shutdown. Shuts down the computer to a point where it is safe to turn off the power. (All file buffers are flushed to disk, and all running processes are stopped.) Users see the message, It is now safe to turn off your computer.

When the forced shutdown approach is used, all services, including WMI, are shut down immediately. Because of this, you will not be able to receive a return value if you are running the script against a remote computer.

6

Forced reboot. Shuts down and then restarts the computer.

When the forced reboot approach is used, all services, including WMI, are shut down immediately. Because of this, you will not be able to receive a return value if you are running the script against a remote computer.

8

Power off. Shuts down the computer and turns off the power (if supported by the computer in question).

12

Forced power off. Shuts down the computer and turns off the power (if supported by the computer in question).

When the forced power off approach is used, all services, including WMI, are shut down immediately. Because of this, you will not be able to receive a return value if you are running the script against a remote computer.

Note

  • The Win32Shutdown method does not have a parameter for locking a workstation, leaving the user logged on. However, workstations can be locked from the command line by using the following command:

  • % windir %\System32\rundll32.exe user32.dll,LockWorkStation

To shut down a computer, your script must include the Shutdown privilege. For more information about including privileges within a WMI script, see "WMI Scripting Primer" in this book.