VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 检测系统驱动器
发表评论(0)作者:, 平台:, 阅读:8462, 日期:2000-03-12
如何知道系统上有哪些外部驱动器?(如软盘、光驱、Zip驱动器等)。如何测试

>> 驱动器中是否有盘?如果有盘,如何弹出?(就像Win95菜单中有“弹出”命令一样)


About Question 1:


using GetDriveType to detect, below is the example for detecting

CD-ROM, others I am not try, you may look up the detail of the funtion,

you can fix it.


'Private Declare Function GetDriveType Lib "kernel32" Alias

"GetDriveTypeA" (ByVal nDrive As String) As Long

'Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias

"GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer

As String) As Long

'Private Const DRIVE_REMOVABLE = 2

'Private Const DRIVE_FIXED = 3

'Private Const DRIVE_REMOTE = 4

'Private Const DRIVE_CDROM = 5

'Private Const DRIVE_RAMDISK = 6



'Place the following code in under a command button or in a menu, etc...


Dim r&, allDrives$, JustOneDrive$, pos%, DriveType&

Dim CDfound As Integer

allDrives$ = Space$(64)

r& = GetLogicalDriveStrings(Len(allDrives$), allDrives$)

allDrives$ = Left$(allDrives$, r&)

Do

pos% = InStr(allDrives$, Chr$(0))

If pos% Then

JustOneDrive$ = Left$(allDrives$, pos%)

allDrives$ = Mid$(allDrives$, pos% + 1, Len(allDrives$))

DriveType& = GetDriveType(JustOneDrive$)

If DriveType& = DRIVE_CDROM Then

CDfound% = True

Exit Do

End If

End If

Loop Until allDrives$ = "" Or DriveType& = DRIVE_CDROM

If CDfound% Then

label1 = "The CD-ROM drive on your system is drive " &

UCase$(JustOneDrive$)

Else: label1 = "No CD-ROM drives were detected on your system."

End If


About question 2:

below is example for how to open & close CD-ROM drive.


'Private Declare Function mciSendString Lib "winmm.dll" Alias_

"mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString

As String, _

ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long



'Open CD drive door

retvalue = mciSendString("set CDAudio door open", returnstring, 127, 0)


'Close CD drive door

retvalue = mciSendString("set CDAudio door closed", returnstring, 127,0)



Regards

- Lu Jun

Mailto:lujun-8@bigfoot.com