'方法一'FormPrivate Function DriveIsCDROM() As Boolean 'Dim ...Set fs0 = CreateObject("scripting.filesystemobject") Set dc0 = fs0.drives DriveIsCDROM = False For Each d0 In dc0 If d0.Drivetype = 4 Then DriveIsCDROM = True Exit Function End If NextEnd FunctionPrivate Sub Form_Load()MsgBox DriveIsCDROM()End Sub'////////////////////////////////'方法二'用API Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
to:vbFly(CSDN是垃圾)
你这要去检测光驱,那要程序不停发消息去判断光驱,
以前我用sysinfo控件做过,使用sysinfo控件的DeviceArrival和DeviceRemoveComplete事件,在事件中判断光驱;现在我要的是不用sysinfo控件。
不用sysinfo等控件能完成这个功能就给分,如何?
'Dim ...Set fs0 = CreateObject("scripting.filesystemobject")
Set dc0 = fs0.drives
DriveIsCDROM = False
For Each d0 In dc0 If d0.Drivetype = 4 Then
DriveIsCDROM = True
Exit Function
End If
NextEnd FunctionPrivate Sub Form_Load()MsgBox DriveIsCDROM()End Sub'////////////////////////////////'方法二'用API
Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
你的方法只是用来判断某个逻辑驱动器是光驱。