Contact Info

Crumbtrail

ActiveXperts.com » Administration » Scripts » WMI » python sample

Win32_Processor python sample code

The foundations for Manageability in Windows is Windows Management Instrumentation (WMI; formerly WBEM) and WMI extensions for Windows Driver Model (WDM).

ActiveXperts Network Monitor provides the ability to build monitor check routines based on WMI. ActiveXperts has collected more than a hundred WMI samples. You can use these samples as a base for new check routines you can write yourself. The Win32_Processor WMI class can be used in ActiveXperts Network Monitor to monitor your servers.


Description

The Win32_Processor WMI class represents a device that can interpret a sequence of machine instructions on a computer running a Windows® operating system. On a multiprocessor machine, one instance of the Win32_Processor class exists for each processor.

Sample Code

import win32com.client
def WMIDateStringToDate(dtmDate):
    strDateTime = ""
    if (dtmDate[4] == 0):
        strDateTime = dtmDate[5] + '/'
    else:
        strDateTime = dtmDate[4] + dtmDate[5] + '/'
    if (dtmDate[6] == 0):
        strDateTime = strDateTime + dtmDate[7] + '/'
    else:
        strDateTime = strDateTime + dtmDate[6] + dtmDate[7] + '/'
        strDateTime = strDateTime + dtmDate[0] + dtmDate[1] + dtmDate[2] + dtmDate[3] + " " + dtmDate[8] + dtmDate[9] + ":" + dtmDate[10] + dtmDate[11] +':' + dtmDate[12] + dtmDate[13]
    return strDateTime

strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("SELECT * FROM Win32_Processor")
for objItem in colItems:
    if objItem.AddressWidth != None:
        print "AddressWidth:" + ` objItem.AddressWidth`
    if objItem.Architecture != None:
        print "Architecture:" + ` objItem.Architecture`
    if objItem.Availability != None:
        print "Availability:" + ` objItem.Availability`
    if objItem.Caption != None:
        print "Caption:" + ` objItem.Caption`
    if objItem.ConfigManagerErrorCode != None:
        print "ConfigManagerErrorCode:" + ` objItem.ConfigManagerErrorCode`
    if objItem.ConfigManagerUserConfig != None:
        print "ConfigManagerUserConfig:" + ` objItem.ConfigManagerUserConfig`
    if objItem.CpuStatus != None:
        print "CpuStatus:" + ` objItem.CpuStatus`
    if objItem.CreationClassName != None:
        print "CreationClassName:" + ` objItem.CreationClassName`
    if objItem.CurrentClockSpeed != None:
        print "CurrentClockSpeed:" + ` objItem.CurrentClockSpeed`
    if objItem.CurrentVoltage != None:
        print "CurrentVoltage:" + ` objItem.CurrentVoltage`
    if objItem.DataWidth != None:
        print "DataWidth:" + ` objItem.DataWidth`
    if objItem.Description != None:
        print "Description:" + ` objItem.Description`
    if objItem.DeviceID != None:
        print "DeviceID:" + ` objItem.DeviceID`
    if objItem.ErrorCleared != None:
        print "ErrorCleared:" + ` objItem.ErrorCleared`
    if objItem.ErrorDescription != None:
        print "ErrorDescription:" + ` objItem.ErrorDescription`
    if objItem.ExtClock != None:
        print "ExtClock:" + ` objItem.ExtClock`
    if objItem.Family != None:
        print "Family:" + ` objItem.Family`
    if objItem.InstallDate != None:
        print "InstallDate:" + WMIDateStringToDate(objItem.InstallDate)
    if objItem.L2CacheSize != None:
        print "L2CacheSize:" + ` objItem.L2CacheSize`
    if objItem.L2CacheSpeed != None:
        print "L2CacheSpeed:" + ` objItem.L2CacheSpeed`
    if objItem.LastErrorCode != None:
        print "LastErrorCode:" + ` objItem.LastErrorCode`
    if objItem.Level != None:
        print "Level:" + ` objItem.Level`
    if objItem.LoadPercentage != None:
        print "LoadPercentage:" + ` objItem.LoadPercentage`
    if objItem.Manufacturer != None:
        print "Manufacturer:" + ` objItem.Manufacturer`
    if objItem.MaxClockSpeed != None:
        print "MaxClockSpeed:" + ` objItem.MaxClockSpeed`
    if objItem.Name != None:
        print "Name:" + ` objItem.Name`
    if objItem.OtherFamilyDescription != None:
        print "OtherFamilyDescription:" + ` objItem.OtherFamilyDescription`
    if objItem.PNPDeviceID != None:
        print "PNPDeviceID:" + ` objItem.PNPDeviceID`
    print "PowerManagementCapabilities:"
    strList = " "
    try :
        for objElem in objItem.PowerManagementCapabilities :
            strList = strList + `objElem` + ","
    except:
        strList = strList + 'null'
    print strList
    if objItem.PowerManagementSupported != None:
        print "PowerManagementSupported:" + ` objItem.PowerManagementSupported`
    if objItem.ProcessorId != None:
        print "ProcessorId:" + ` objItem.ProcessorId`
    if objItem.ProcessorType != None:
        print "ProcessorType:" + ` objItem.ProcessorType`
    if objItem.Revision != None:
        print "Revision:" + ` objItem.Revision`
    if objItem.Role != None:
        print "Role:" + ` objItem.Role`
    if objItem.SocketDesignation != None:
        print "SocketDesignation:" + ` objItem.SocketDesignation`
    if objItem.Status != None:
        print "Status:" + ` objItem.Status`
    if objItem.StatusInfo != None:
        print "StatusInfo:" + ` objItem.StatusInfo`
    if objItem.Stepping != None:
        print "Stepping:" + ` objItem.Stepping`
    if objItem.SystemCreationClassName != None:
        print "SystemCreationClassName:" + ` objItem.SystemCreationClassName`
    if objItem.SystemName != None:
        print "SystemName:" + ` objItem.SystemName`
    if objItem.UniqueId != None:
        print "UniqueId:" + ` objItem.UniqueId`
    if objItem.UpgradeMethod != None:
        print "UpgradeMethod:" + ` objItem.UpgradeMethod`
    if objItem.Version != None:
        print "Version:" + ` objItem.Version`
    if objItem.VoltageCaps != None:
        print "VoltageCaps:" + ` objItem.VoltageCaps`