Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Use the WMI classes that obtain data from performance counters to access and refresh data about computer performance. For other examples, see the TechNet ScriptCenter at https://www.microsoft.com/technet. For more information, see Performance Libraries and WMI and Monitoring Performance Data.
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
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 | ||
---|---|---|---|
...obtain the performance counter data that I can see in the Perfmon utility in a script? | Use classes that have names that begin with "Win32_PerfFormattedData", for example Win32_PerfFormattedData_PerfProc_Process. Properties with names like PageFileBytes correspond to performance counters you see in Perfmon. The "Win32_PerfFormattedData" classes calculate the final values of counters for you. |
||
...get on-going performance data for a single process, disk drive, and other data? | Use the Win32_PerfFormattedData_PerfProc_Process or the appropriate formatted Performance Counter Class and the SWbemObjectEx.Refresh_ method. For more information, see Scripting with SWbemObject. In C++, use IWbemConfigureRefresher::AddObjectByPath and IWbemRefresher::Refresh. For more information, see Monitoring Performance Data. The following script runs until the computer is restarted, WMI is stopped, or the script is stopped. To stop the script manually, use Task Manager to stop the process. To stop it programmatically, use the Terminate method in the Win32_Process class.
|
||
...get on-going performance data for all processes without repeated polling? | Use classes that have names that begin with "Win32_PerfFormattedData" and an SWbemRefresher object. The refresher holds the objects so you do not need to get the collection repeatedly. A minimum of two values are needed to calculate performance data because most counters are rate counters. The first time you display the refresher data it is empty. The following script runs indefinitely until the computer is rebooted, WMI is stopped, or the script is stopped. To stop the script manually, use Task Manager to stop the process. To stop it programmatically, use the Terminate method in the Win32_Process class.
|
||
...get and calculate performance data for processes on Windows 2000? | Use the "Win32_PerfRawData" classes, such as Win32_PerfRawData_PerfProc_Process. Get the property data, such as PercentProcessorTime, twice for a specific process. Look up the formula specified in the CounterType qualifier for the property and calculate. The CounterType in the example is PERF_100NSEC_TIMER_INV. For more information, see Monitoring Performance Data. The following script runs indefinitely until the computer is rebooted, WMI is stopped, or the script is stopped. To stop the script manually, use Task Manager to stop the process. To stop it programmatically, use the Terminate method in the Win32_Process class.
|
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today