0

我试图避免在运行我的应用程序时显示“驱动器未准备好”或“无光盘”的 Windows 警报。这是我的 fsp.py

import os, win32api
oer = win32api.SetErrorMode( 1 ) #note that SEM_FAILCRITICALERRORS = 1
def check(drive):
    try:
        with open(drive+'\\fsp.check', 'w') as drive_check:
            drive_check.write('000')
        os.unlink(drive+'\\fsp.check')
        return True
    except Exception, e:
        win32api.SetErrorMode(oer)
        return False

和 mount.py 告诉已安装的设备。

import os
def Query(letters):
#Get mounted devices
    try:
        for l in letters:
            l = l+':\\'
            if os.path.isdir(l):
                yield l
    except Exception, queryex:
        pass
        #print str(queryex)
def main():   
    try:
        return Query(('abefghijklmnopqrstuvwxyz').upper())
    except Exception, mainex:
        pass
        #print str(mainex)        
if __name__ == '__main__':
main()

这是我尝试使用这两个模块的方法。例子.py

import mount, fsp
for a in mount.main():
    if fsp.check(a) == True:
        print 'Monted and Ready ', a
    else:
        print 'Mounted but not ready ',a

但我仍然收到 Windows 警报。如何避免。至少通过使用 fsp.py 代码。

4

0 回答 0