python:pywintypes.com_从CDRom而非HD运行时出错

python:pywintypes.com_从CDRom而非HD运行时出错,python,pywin32,cx-freeze,cd-rom,Python,Pywin32,Cx Freeze,Cd Rom,我有一个较大程序的一小部分代码,该程序只检查驱动器号和CDROM的状态 import wmi print '--checkCDContent--' c=wmi.WMI() cdrom = c.Win32_CDROMDrive() status = cdrom[0].MediaLoaded drive = cdrom[0].Drive print drive, status 作为大型程序的一部分,我必须使用cxFreeze编译代码以创建一个exe。为了测试我的问题,我单独使用了上面的代码来

我有一个较大程序的一小部分代码,该程序只检查驱动器号和CDROM的状态

import wmi

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

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

print drive, status
作为大型程序的一部分,我必须使用cxFreeze编译代码以创建一个exe。为了测试我的问题,我单独使用了上面的代码来复制它

当我从硬盘上运行.exe时,它运行正常。当我从CD本身运行它时,我的最终目标是得到以下错误

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
    self._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)
我怀疑它会出现此错误,因为代码实际上是从CD运行的,同时它试图获取CD的状态更新。有人能证实这一点并提出解决方案吗