5

I'm having the problem with the WMI availability on logon.

Right after reboot I open cmd and with python interpreter:

>>> 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 minutes later I open another cmd and python interpreter:

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=@>]
>>>

NOTE: the first cmd still keeps saying AttributeError even 5 minutes later.

NOTE 2: if I logout and login wmi is available, so it is somehow effected by reboot

with process explorer I check the environmental variables and they are the same for both cmds

What could that be? Please help.

UPDATE: Apparently the problem is connecting to the wbem services:

>>> 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)
>>>

NOTE 3: wmic os always worked.

NOTE 4: re-installing pywin32 package didn't help. Neither did Re-registering/re-compiling the WMI components and resetting of the WMI database (as recommended here)

NOTE 5: my 4 Other laptops don't have this problem.

Also wmiprov.log has:

(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) : ***************************************

NOTE 6: the WMIDiag tool report is at my dropbox

8
  • @Lizz Thanks for your effort. The queries are to the local host (thus the initialization is wmi.WMI() without the parameters of host name and user/password) and both started under admin privileges. Also wmic works fine and 'wmic os' query (which is the same as I'm trying to do with python) outputs the expected result. I ran the WMIDiag diagnostics tool and found some errors but they shouldn't result in what I get. (you can see it in my dropbox: dl.dropbox.com/u/61886092/… ) Commented Oct 29, 2012 at 14:39
  • Actually the errors might be the cause - they point to WMI corruption, according to the link below. Luckily there's a hotfix. The error is "0x80041002 - (WBEM_E_NOT_FOUND)" and the fix is here: support.microsoft.com/kb/2465990. Can you apply it and let us know? If it isn't fixed after applying and rebooting, then see the KB for disabling the Resultant Set of Policy (RSoP) logging policy.
    – Lizz
    Commented Oct 30, 2012 at 5:27
  • @Lizz both the hotfix and turning off RSoP logging policy did not work. I formatted the hard drive and reinstalled os (including some of the drivers and all windows updates) - that didn't help either. That makes me think it's something with the machine. It's a every powerful laptop (lenovo w520) with i7 and I have Pyro 60G SSD there. Maybe the problem is that it's too fast? Or could the drive be faulty? Commented Oct 30, 2012 at 21:59
  • Speed shouldn't be problem but you can add a sleep 500ms to make sure. Check System log for HD errors. Which OS is installed on it? If not too much trouble, try different OS, like XP or 7. I trust it doesn't get a different policy (Active Directory, security, etc) than other computers, and it doesn't have odd software. For comparison, try to match setup of a good PC. Since we don't have full insight to your environment, troubleshooting requires more Q/A. Sorry :(
    – Lizz
    Commented Oct 31, 2012 at 8:02
  • @Lizz The OS is Win 7 Enterprise. I've installed all the drivers possible and updated the BIOS - nothing worked. So I put the original image of Win 7 Professional on this machine and after all updates and drivers installed WMI works as expected. What surprises me is why re-installing the Enterprise os haven't fixed the problem. I know the image on CD is good, I've installed it on many machines before. Anyway, the problem is solved now. Thanks. Commented Nov 2, 2012 at 11:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.