WMI不在部分时间后可用

2024-06-26 04:28:18 发布

您现在位置:Python中文网/ 问答频道 /正文

登录时WMI可用性有问题。在

重新启动后,我打开cmd并使用python解释器:

>>> import wmi
>>> c = wmi.WMI()
>>> c.Win32_OperatingSystem()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\wmi.py", line 1147, in __getattr__
    return getattr (self._namespace, attribute)
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516, in
__getattr__
    raise AttributeError("%s.%s" % (self._username_, attr))
AttributeError: winmgmts:.Win32_OperatingSystem
>>>

5分钟后,我打开另一个cmd和python解释器:

^{pr2}$

注意:即使5分钟后,第一个cmd仍然会说AttributeError。在

注意2:如果我注销并且登录wmi可用,那么它会受到重新启动的影响

使用process explorer,我检查环境变量,两个cmd的环境变量都相同

那会是什么? 请帮忙。在

更新:显然问题是连接到wbem服务:

>>> import win32com.client
>>> win32com.client.Dispatch('WbemScripting.SWbemLocator')
<COMObject WbemScripting.SWbemLocator>
>>> wmi_service= win32com.client.Dispatch('WbemScripting.SWbemLocator')
>>> wbem_service =  wmi_service.ConnectServer('.','root/cimv2')
>>> wbem_service
<COMObject <unknown>>
>>> items = wbem_service.ExecQuery('Select * from Win32_OperatingSystem')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<COMObject <unknown>>", line 3, in ExecQuery
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 282, in
_ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes
) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemServicesEx
', u'Generic failure ', None, 0, -2147217407), None)
>>>

注3:wmic os始终有效。在

注意4:重新安装pywin32包没有帮助。{重新注册WMI}和重新注册WMI}都不建议

注意5:我的其他4台笔记本电脑没有这个问题。

同时wmiprov.log文件有:

(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248587) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248587) : C:\Windows\system32\drivers\ndis.sys[MofResourceName](Mon Oct 29 11:40:07 2012.248587) : 
(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248587) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248587) : C:\Windows\system32\drivers\en-US\ndis.sys.mui[MofResourceName](Mon Oct 29 11:40:07 2012.248587) : 
(Mon Oct 29 11:40:07 2012.248587) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248603) : C:\Windows\system32\DRIVERS\wmiacpi.sys[MofResource](Mon Oct 29 11:40:07 2012.248603) : 
(Mon Oct 29 11:40:07 2012.248603) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : ***************************************
(Mon Oct 29 11:40:07 2012.248603) : Could not get pointer to binary resource for file:
(Mon Oct 29 11:40:07 2012.248603) : C:\Windows\system32\DRIVERS\monitor.sys[MonitorWMI](Mon Oct 29 11:40:07 2012.248603) : 
(Mon Oct 29 11:40:07 2012.248603) : ***************************************

注6:WMIDiag工具报告位于my dropbox


Tags: incmdclientgetservicelinenotwmi