Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
WMI tasks for services obtain information about services, including dependent or antecedent services. 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 which services are running and which ones are not? | Use the Win32_Service class to check the state of all of the services. The state property lets you know if a service is stopped or running.
|
||||
...stop Power Users from starting certain services? | Use the Win32_Service class and the ChangeStartMode method to set the StartMode property to Disabled. Disabled services cannot be started, and, by default, Power Users cannot change the start mode of a service.
|
||||
...start and stop services? | Use the Win32_Service class and the StopService and StartService methods.
|
||||
...change service account passwords using a script? | Use the Win32_Service class and the Change method.
|
||||
..determine which services I can stop? | Use the Win32_Service class, and check the value of the AcceptStop property.
|
||||
...find the services that must be running before I can start the DHCP service? | Query for ASSOCIATORS OF the Win32_Service class named "DHCP" that are in the Win32_DependentService class and have "Dependent" in the Role property. Role means the role of the DHCP service: in this case, it is dependent on the other services that are being started.
|
||||
...find the services that require the WMI service (Winmgmt) service to be running before they can start? | Query for ASSOCIATORS OF the Win32_Service class named "DHCP" that are in the Win32_DependentService class and have "Antecendent" in the Role property. Role means the role of the rasman service: in this case, it is antecedent to must be started before the dependent services.
|
Related topics
`