When I run the following code:
def get_process_info(pid):
c = wmi.WMI(namespace='root\\cimv2')
obj = c.Win32_Process(ProcessId = pid)[0]
print "VirtualSize:", obj.wmi_property('VirtualSize').type
print "VirtualSize:", obj.wmi_property('VirtualSize').Value
def get_perf_info(pid):
c = wmi.WMI(namespace='root\\cimv2')
obj = c.Win32_PerfFormattedData_PerfProc_Process(IDProcess = pid)[0]
print "PrivateBytes:", obj.wmi_property('PrivateBytes').type
print "PrivateBytes:", obj.wmi_property('PrivateBytes').Value
Against a process which is using a lot of memory I get this:
VirtualSize: uint64
VirtualSize: 5015498752
PrivateBytes: uint64
PrivateBytes: 4294967295
Note that both are listed as being 64-bit values but the PrivateBytes values is 0xFFFFFFFF. If I use "WMI Explorer" I can see the PrivateBytes value is larger than 32-bits:

My question is how can I access PrivateBytes in its full 64-bit glory?
Is there a completely other way to read the WMI from python besides this WMI module?
You can use wmic which provides a command-line interface for WMI :
def find_privatebytes(pid):
with os.popen('wmic process list full /format:csv') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
crow = 0
col_pid = 0
col_pb = 0
for row in reader:
if len(row) == 0:
continue
if crow == 0:
col_pid = row.index("ProcessId")
col_pb = row.index("PrivatePageCount")
crow += 1
elif int(row[col_pid]) == pid:
return int(row[col_pb])
return 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With