difference 32- vs 64-bits
Closed this issue · 32 comments
On a Win7-32 machine a cwmi query of Win32_Processor doesn't find any value for ProcessorID; but on a Win7-64 machine it does. Yet on both machines the Go wmi package gets a value in both cases. I also checked the Python WMI package that uses PyWin32, and that finds the ProcessorID on both too.
I had no issues running the following on a Windows x86 SP1 machine using python 3.4.
>>> import cwmi
>>> cwmi.query('SELECT * FROM Win32_Processor')
What version of python are you using?
3.7 (not sure of the minor, probably 3.7.2)
Same test machine, using python 3.7.3, did not reproduce the issue either. I'm unsure what (if any) special permissions are required for that query though. I was running as a user who is part of the administrators group, but the python process was not run as administrator.
I just ran it as an ordinary user (but like you, part of the admin group).
Was ProcessorID
the only field that appeared to be missing?
Yes, the others I retrieved (about 5 of them) all came back same as WMI & Go's wmi. Also another query of the base board works fine.
Unsure if encoding is the issue here, but I created this branch to address this possibility. Please test this branch https://github.com/fireeye/cWMI/tree/fix/bstr_encoding and let me know if that fixes this issue.
I tried it on my Win7-32 system but it doesn't work:
with cwmi.WMI(computer) as wmi:
File "C:\bin\python\lib\site-packages\cwmi\wmi.py", line 2006, in __enter__
self.init()
File "C:\bin\python\lib\site-packages\cwmi\wmi.py", line 2013, in init
super(WMI, self).init()
File "C:\bin\python\lib\site-packages\cwmi\com.py", line 184, in init
winapi.CoInitializeEx(None, self._coinit)
File "C:\bin\python\lib\site-packages\cwmi\winapi.py", line 716, in CoInitializeEx
return _CoInitializeEx(reserved, co_init)
File "C:\bin\python\lib\site-packages\cwmi\winapi.py", line 682, in RAISE_NON_ZERO_ERR
raise ctypes.WinError(result)
SError: [WinError -2147417850] Cannot change thread mode after it is set.
I'm using a locally installed (not system-wide) WinPython. The application I'm using does not use threads (at least I don't import threading; but it does use subprocesses).
Are you using cwmi
with something that has potentially called CoInitialize()
? That looks similar to #1
I don't know! But possibly since in that program I have two functions, one using WMI and the other using cwmi so I can compare their output. Maybe WMI does that?
That is likely. Try switching calling into cwmi first then WMI. That may resolve the COM initialization issue.
Tried that and now cwmi works. However, it still doesn't find the Win32_Processor ProcessorID; yet both WMI.py and the Go wmi libraries find it.
Thus far I am unable to reproduce the issue. If you're okay with it, would you post the value for the other sources give? The reason I ask is that I have tried encoding null bytes into the string, and those appear to work fine - even without the fix in the branch.
Oh, did you use the branch that attempted to fix the (possible) BSTR issue? https://github.com/fireeye/cWMI/tree/fix/bstr_encoding
Yes, I used the bstr_encoding version.
Here are my results on Windows 7-32 bits:
Python 3.7.2 cwmi
Win32_BaseBoard/Manufacturer: Acer
Win32_BaseBoard/Name: BaseBoard
Win32_BaseBoard/Version: V3.05(DDR2)
Win32_BaseBoard/Product: AOD255
Win32_Processor/Manufacturer: GenuineIntel
Win32_Processor/Name: Intel(R)Atom(TM)CPUN450@1.66GHz
Win32_Processor/SocketDesignation: CPU
Py 3.7.2 WMI
Win32_BaseBoard/Manufacturer: Acer
Win32_BaseBoard/Name: BaseBoard
Win32_BaseBoard/Version: V3.05(DDR2)
Win32_BaseBoard/Product: AOD255
Win32_Processor/Manufacturer: GenuineIntel
Win32_Processor/Name: Intel(R)Atom(TM)CPUN450@1.66GHz
Win32_Processor/ProcessorID: BFE9FBFF000106CA
Win32_Processor/SocketDesignation: CPU
Go 1.10.8
Win32_BaseBoard/Manufacturer: Acer
Win32_BaseBoard/Name: BaseBoard
Win32_BaseBoard/Version: V3.05(DDR2)
Win32_BaseBoard/Product: AOD255
Win32_Processor/Manufacturer: GenuineIntel
Win32_Processor/Name: Intel(R)Atom(TM)CPUN450@1.66GHz
Win32_Processor/ProcessorID: BFE9FBFF000106CA
Win32_Processor/SocketDesignation: CPU
Are you using the helper cwmi.query()
? Can you show me how you are using cwmi
? If I had an idea how the it was being used I may have a better idea of what the issue might be.
Here's an extract:
# Win32_Processor query
with cwmi.WMI(r'root\cimv2') as wmi:
query = 'SELECT Manufacturer,Name,ProcessorID,SocketDesignation FROM Win32_Processor'
with wmi.ExecQuery('WQL', query, 0, None) as iterator:
while True:
try:
with iterator.Next(cwmi.WBEM_INFINITE) as obj:
obj.BeginEnumeration(0)
while True:
try:
name, value, _, _ = obj.Next(0)
if not name.startswith('_'):
value = _value(value)
if value is not None:
print(f'Win32_Processor/{name}: {value}')
except WindowsError:
break
obj.EndEnumeration()
except WindowsError:
break
def _value(value):
value = cwmi.V_TO_TYPE(value)
if value != 'NULL':
value = re.sub(r'\s+', '', str(value)).strip()
if value and value.replace(value[0], ''):
return value
# else return None
Now I'm wondering if the problem is with my own _value()
function rather than with cwmi?
Would you please try using the helper cwmi.query()
?
Looks like the problem is with my code?
Here's the code I used with cwmi.query()
:
import cwmi
query = ('SELECT Manufacturer,Name,ProcessorID,'
'SocketDesignation FROM Win32_Processor')
result = cwmi.query(r'root\cimv2', query)
for key, value in result.items():
print(key)
for k, v in value.items():
print(f' {k}={v}')
And here's the output:
NULL
__PATH=NULL
__NAMESPACE=NULL
__SERVER=NULL
__DERIVATION=4151368
__PROPERTY_COUNT=4
__RELPATH=NULL
__DYNASTY=NULL
__SUPERCLASS=NULL
__CLASS=Win32_Processor
__GENUS=2
Manufacturer=GenuineIntel
Name=Intel(R) Atom(TM) CPU N450 @ 1.66GHz
ProcessorId=BFE9FBFF000106CA
SocketDesignation=CPU
Okay. If you are using the branch I had created would you please switch to master and confirm that the output is the same.
How do I do that? I just downloaded before?
If you had checked out the https://github.com/fireeye/cWMI/tree/fix/bstr_encoding branch just checkout master. If you hadn't done that or just pip install cwmi
then you're using master and you don't need to do anything. I had thought that you were using the fix branch.
I just clicked the link you gave and used that for the bstr_encoding one. For the original one I used pip.
In that case you can just force a reinstall using pip pip install --force-reinstall cwmi
. Depending on your setup you may need to add the --upgrade
option so pip install --force-reinstall --upgrade cwmi
.
I did the pip command: pip install --force-reinstall --upgrade cwmi
. Then I ran exactly the same code as above using cwmi.query()
. Here's the output:
NULL
__PATH=NULL
__NAMESPACE=NULL
__SERVER=NULL
__DERIVATION=4020088
__PROPERTY_COUNT=4
__RELPATH=NULL
__DYNASTY=NULL
__SUPERCLASS=NULL
__CLASS=Win32_Processor
__GENUS=2
Manufacturer=GenuineIntel
Name=Intel(R) Atom(TM) CPU N450 @ 1.66GHz
ProcessorId=BFE9FBFF000106CA
SocketDesignation=CPU
So as far as I can tell it is returning all the information it is supposed do.
Thank you. The output looks like it is the same to me so I'm going to remove that branch - since it is not needed. Does the output match the other projects at this point? The output from cwmi.query()
that is.
Not sure what you're asking?
Is the data from cwmi.query()
the same as the python WMI project and Go wmi?
Yes.
Okay. I've removed that the fix branch as it appears to not of been needed.
Do you still think this there is an issue?
Sorry, I've lost track, so not sure.