登录时我遇到了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解释器:
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wmi
>>> c = wmi.WMI()
>>> c.Win32_OperatingSystem()
[<_wmi_object: \\W520-ALEX-WIN7\root\cimv2:Win32_OperatingSystem=@>]
>>>
注意:即使5分钟后,第一个cmd仍然会继续说 AttributeError 。
注意2:如果我注销并登录wmi可用,那么它会以某种方式重启
使用进程资源管理器我检查环境变量并且它们对于两个cmds都是相同的
那可能是什么? 请帮忙。
更新:显然问题是连接到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数据库(按照建议here)
注意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