WMI with IronPython

From IronPython Cookbook

(Difference between revisions)
Line 1: Line 1:
-
An example from [http://vastusutra.blogspot.com/2007/09/wmi-on-local-system.html Vasta Sutra], of using the managed interface to WMI on the local system.
+
Examples from [http://vastusutra.blogspot.com/ Vasta Sutra], of using the managed interface to WMI on the local system.
These examples use objects from the [http://msdn2.microsoft.com/en-us/library/system.management.aspx System.Management] assembly:
These examples use objects from the [http://msdn2.microsoft.com/en-us/library/system.management.aspx System.Management] assembly:

Revision as of 15:46, 26 October 2007

Examples from Vasta Sutra, of using the managed interface to WMI on the local system.

These examples use objects from the System.Management assembly:

import clr
clr.AddReference("System.Management")
from System.Management import (
    ManagementObject,
    ManagementObjectSearcher
)

mo = ManagementObject("Win32_Processor.DeviceID='CPU0'")
for p in mo.Properties: 
    print p.Name, '=', p.Value

query = ManagementObjectSearcher("Select * from Win32_Processor")
mo = query.Get().GetEnumerator().next()

mo = ManagementObject("Win32_PerfFormattedData_PerfOS_Processor.Name='_total'")
for p in mo.Properties: 
    print p.Name, '=', p.Value


This next example reports CPU utilisation:

import clr
clr.AddReference("System.Management")
from System.Management  import ManagementObject
from System.Threading import Thread

while True:
    mo = ManagementObject("Win32_PerfFormattedData_PerfOS_Processor.Name='_total'")
    print mo["PercentProcessorTime"]
    Thread.Sleep(5000)


Back to Contents.

TOOLBOX
LANGUAGES