Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
WMI Tasks: Desktop Management
WMI tasks for desktop management can exert control and obtain data from either a remote desktop or a local computer. For example, you can determine whether the screensaver on a local computer requires a password. WMI also gives you the ability shut down a remote computer. For other examples, see the TechNet ScriptCenter at https://www.microsoft.com/technet.
The script examples shown in this topic obtain data only from the local computer. For more information about how to use the script to obtain data from remote computers, see Connecting to WMI on a Remote Computer.
The following procedure describes how to run a script.
To run a script
- Copy the code and save it in a file with a .vbs extension, such as filename.vbs. Ensure that your text editor does not add a .txt extension to the file.
- Open a command prompt window and navigate to the directory where you saved the file.
- Type cscript filename.vbs at the command prompt.
- If you cannot access an event log, check to see if you are running from an Elevated command prompt. Some Event Log, such as the Security Event Log, may be protected by User Access Controls (UAC).
Note
By default, cscript displays the output of a script in the command prompt window. Because WMI scripts can produce large amounts of output, you might want to redirect the output to a file. Type cscript filename.vbs > outfile.txt at the command prompt to redirect the output of the filename.vbs script to outfile.txt.
The following table lists script examples that can be used to obtain various types of data from the local computer.
| How do I... | WMI classes or methods | ||||
|---|---|---|---|---|---|
| ...determine if a remote computer has booted up in the Safe Mode with Networking state? | Use the Win32_ComputerSystem class and check the value of the PrimaryOwnerName property.
|
||||
| ...determine if a computer screensaver requires a password? | Use the Win32_Desktop class and check the value of the ScreenSaverSecure property.
|
||||
| ...verify that a computer screen has been set for 800 pixels by 600 pixels? | Use the Win32_DesktopMonitor class and check the values of the properties ScreenHeight and ScreenWidth.
|
||||
| ...determine how long a computer has been running? | Use the Win32_OperatingSystem class and the LastBootUpTime property. Subtract that value from the current time to get the system uptime.
|
||||
| ...reboot or shut down a remote computer? | Use the Win32_OperatingSystem class and the Win32Shutdown method. You must include the RemoteShutdown privilege when connecting to WMI. For more information, see Executing Privileged Operations Using VBScript. Unlike the Shutdown method on Win32_OperatingSystem, the Win32Shutdown method allows you to set flags to control the shutdown behavior.
|
||||
| ...determine what applications automatically run each time I start Windows? | Use the Win32_StartupCommand class.
|
Related topics
Feedback
Was this page helpful?
