Win32_Process - WMI sample in Python

The foundations for Manageability in Windows 7/2008/Vista/XP/2000 and Millennium Edition/'98 are 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.

On this site, you can find many WMI samples.


Win32_Process

Description

The Win32_Process WMI class represents a sequence of events on a Windows operating system. A descendent or member of this class is a sequence that consists of an interaction of one or more processors or interpreters, some executable code, and a set of inputs, for example, a client application running on a Windows system.

Example(s)

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_Process")
for objItem in colItems:
    if objItem.Caption != None:
        print "Caption:" + ` objItem.Caption`
    if objItem.CommandLine != None:
        print "CommandLine:" + ` objItem.CommandLine`
    if objItem.CreationClassName != None:
        print "CreationClassName:" + ` objItem.CreationClassName`
    if objItem.CreationDate != None:
        print "CreationDate:" + WMIDateStringToDate(objItem.CreationDate)
    if objItem.CSCreationClassName != None:
        print "CSCreationClassName:" + ` objItem.CSCreationClassName`
    if objItem.CSName != None:
        print "CSName:" + ` objItem.CSName`
    if objItem.Description != None:
        print "Description:" + ` objItem.Description`
    if objItem.ExecutablePath != None:
        print "ExecutablePath:" + ` objItem.ExecutablePath`
    if objItem.ExecutionState != None:
        print "ExecutionState:" + ` objItem.ExecutionState`
    if objItem.Handle != None:
        print "Handle:" + ` objItem.Handle`
    if objItem.HandleCount != None:
        print "HandleCount:" + ` objItem.HandleCount`
    if objItem.InstallDate != None:
        print "InstallDate:" + WMIDateStringToDate(objItem.InstallDate)
    if objItem.KernelModeTime != None:
        print "KernelModeTime:" + ` objItem.KernelModeTime`
    if objItem.MaximumWorkingSetSize != None:
        print "MaximumWorkingSetSize:" + ` objItem.MaximumWorkingSetSize`
    if objItem.MinimumWorkingSetSize != None:
        print "MinimumWorkingSetSize:" + ` objItem.MinimumWorkingSetSize`
    if objItem.Name != None:
        print "Name:" + ` objItem.Name`
    if objItem.OSCreationClassName != None:
        print "OSCreationClassName:" + ` objItem.OSCreationClassName`
    if objItem.OSName != None:
        print "OSName:" + ` objItem.OSName`
    if objItem.OtherOperationCount != None:
        print "OtherOperationCount:" + ` objItem.OtherOperationCount`
    if objItem.OtherTransferCount != None:
        print "OtherTransferCount:" + ` objItem.OtherTransferCount`
    if objItem.PageFaults != None:
        print "PageFaults:" + ` objItem.PageFaults`
    if objItem.PageFileUsage != None:
        print "PageFileUsage:" + ` objItem.PageFileUsage`
    if objItem.ParentProcessId != None:
        print "ParentProcessId:" + ` objItem.ParentProcessId`
    if objItem.PeakPageFileUsage != None:
        print "PeakPageFileUsage:" + ` objItem.PeakPageFileUsage`
    if objItem.PeakVirtualSize != None:
        print "PeakVirtualSize:" + ` objItem.PeakVirtualSize`
    if objItem.PeakWorkingSetSize != None:
        print "PeakWorkingSetSize:" + ` objItem.PeakWorkingSetSize`
    if objItem.Priority != None:
        print "Priority:" + ` objItem.Priority`
    if objItem.PrivatePageCount != None:
        print "PrivatePageCount:" + ` objItem.PrivatePageCount`
    if objItem.ProcessId != None:
        print "ProcessId:" + ` objItem.ProcessId`
    if objItem.QuotaNonPagedPoolUsage != None:
        print "QuotaNonPagedPoolUsage:" + ` objItem.QuotaNonPagedPoolUsage`
    if objItem.QuotaPagedPoolUsage != None:
        print "QuotaPagedPoolUsage:" + ` objItem.QuotaPagedPoolUsage`
    if objItem.QuotaPeakNonPagedPoolUsage != None:
        print "QuotaPeakNonPagedPoolUsage:" + ` objItem.QuotaPeakNonPagedPoolUsage`
    if objItem.QuotaPeakPagedPoolUsage != None:
        print "QuotaPeakPagedPoolUsage:" + ` objItem.QuotaPeakPagedPoolUsage`
    if objItem.ReadOperationCount != None:
        print "ReadOperationCount:" + ` objItem.ReadOperationCount`
    if objItem.ReadTransferCount != None:
        print "ReadTransferCount:" + ` objItem.ReadTransferCount`
    if objItem.SessionId != None:
        print "SessionId:" + ` objItem.SessionId`
    if objItem.Status != None:
        print "Status:" + ` objItem.Status`
    if objItem.TerminationDate != None:
        print "TerminationDate:" + WMIDateStringToDate(objItem.TerminationDate)
    if objItem.ThreadCount != None:
        print "ThreadCount:" + ` objItem.ThreadCount`
    if objItem.UserModeTime != None:
        print "UserModeTime:" + ` objItem.UserModeTime`
    if objItem.VirtualSize != None:
        print "VirtualSize:" + ` objItem.VirtualSize`
    if objItem.WindowsVersion != None:
        print "WindowsVersion:" + ` objItem.WindowsVersion`
    if objItem.WorkingSetSize != None:
        print "WorkingSetSize:" + ` objItem.WorkingSetSize`
    if objItem.WriteOperationCount != None:
        print "WriteOperationCount:" + ` objItem.WriteOperationCount`
    if objItem.WriteTransferCount != None:
        print "WriteTransferCount:" + ` objItem.WriteTransferCount`