开发者

python: pywintypes.com_error when running from CDRom but not HD

I have a small bit of code (part of a larger program) that just checks the drive letter and status of the CDROM

import wmi

print '--checkCDContent--'
c=wmi.WMI()

cdrom = c.Win32_CDROMDrive()
status = cdrom[0].MediaLoaded
drive = cdrom[0].Drive

print drive, status

As part of the larger program I have to compile the code using cxFreeze to create an exe. To test my problem I used the code above alone to replicate it.

When I run the .exe from the hard drive it runs correctly. When I run it from the CD itself (my end goal) I get the following error

X:\>CDrun.exe
--checkCDContent--
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module>
    exec code in m.__dict__
  File "CDrun.py", line 6, in <module>
  File "C:\Python27\lib\site-packages\wmi-1.4.9-py2.7-win32.egg\wmi.py", line 1145, in __getattr__
    return self._cached_classes (attribute)
  File "C:\Python27\lib\site-packages\wmi-1.4.9-py2.7-win32.egg\wmi.py", line 1156, in _cached_classes
    se开发者_StackOverflow社区lf._classes_map[class_name] = _wmi_class (self, self._namespace.Get (class_name))
  File "C:\Python27\lib\site-packages\wmi-1.4.9-py2.7-win32.egg\wmi.py", line 783, in __init__
if namespace:
  File "C:\Python27\lib\site-packages\wmi-1.4.9-py2.7-win32.egg\wmi.py", line 1145, in __getattr__
    return self._cached_classes (attribute)
  File "C:\Python27\lib\site-packages\wmi-1.4.9-py2.7-win32.egg\wmi.py", line 1156, in _cached_classes
   self._classes_map[class_name] = _wmi_class (self, self._namespace.Get (class_name))
  File "<COMObject winmgmts:>", line 3, in Get
  File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 272, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'SWbemServicesEx', u'Not found ', None, 0, -2147217406), None)

What I suspect is that it is having this error because the code is in effect running from the CD at the same time its trying to get a status update of the CD. Can anybody validate this and suggest a solution?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜