请问98系统下本机光驱路径如何认定?

smenya 2003-08-21 05:32:54
3Q
...全文
48 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xinshou1979330 2003-08-21
  • 打赏
  • 举报
回复
Private Sub Form_Load()
Dim val As Integer
GetCDRom
End Sub
Private Function GetCDRom() As String
Dim LDs As Long, Cnt As Long, sDriver As String
LDs = GetLogicalDrives
For Cnt = 0 To 25
If (LDs And 2 ^ Cnt) <> 0 Then
sDriver = Chr$(65 + Cnt) & ":\"
If IsCDRom(sDriver) Then
Run sDriver
End If
End If
Next Cnt
End Function

Private Function IsCDRom(ByVal sDriver As String) As Boolean
Select Case GetDriveType(sDriver)
Case 2: IsCDRom = False 'Me.Print "Removable"
Case 3: IsCDRom = False ' Me.Print "Drive Fixed"
Case Is = 4: IsCDRom = False ' Me.Print "Remote"
Case Is = 5: IsCDRom = True ' Me.Print "Cd-Rom"
Case Is = 6: IsCDRom = False ' Me.Print "Ram disk"
Case Else: IsCDRom = False ' Me.Print "Unrecognized"
End Select
End Function


这样试一下
liul17 2003-08-21
  • 打赏
  • 举报
回复
上面的函数帮助在这
GetLogicalDriveStrings

VB声明
Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
说明
获取一个字串,其中包含了当前所有逻辑驱动器的根驱动器路径
返回值
Long,装载到lpBuffer的字符数量(排除空中止字符)。如缓冲区的长度不够,不能容下路径,则返回值就变成要求的缓冲区大小。零表示失败。会设置GetLastError
参数表
参数 类型及说明
nBufferLength Long,lpBuffer字串的长度
lpBuffer String,用于装载逻辑驱动器名称的字串。每个名字都用一个NULL字符分隔,在最后一个名字后面用两个NULL表示中止(空中止)
liul17 2003-08-21
  • 打赏
  • 举报
回复
还有一个

Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Load()
Dim strSave As String
'Set the graphic mode to persistent
Me.AutoRedraw = True
'Create a buffer to store all the drives
strSave = String(255, Chr$(0))
'Get all the drives
ret& = GetLogicalDriveStrings(255, strSave)
'Extract the drives from the buffer and print them on the form
For keer = 1 To 100
If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
Me.Print Left$(strSave, InStr(1, strSave, Chr$(0)) - 1)
strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
Next keer
End Sub

liul17 2003-08-21
  • 打赏
  • 举报
回复
使用函数,给你个例子

Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
Dim Serial As Long, VName As String, FSName As String
'Create buffers
VName = String$(255, Chr$(0))
FSName = String$(255, Chr$(0))
'Get the volume information
GetVolumeInformation "C:\", VName, 255, Serial, 0, 0, FSName, 255
'Strip the extra chr$(0)'s
VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
MsgBox "The Volume name of C:\ is '" + VName + "', the File system name of C:\ is '" + FSName + "' and the serial number of C:\ is '" + Trim(Str$(Serial)) + "'", vbInformation + vbOKOnly, App.Title
End Sub

zqfleaf 2003-08-21
  • 打赏
  • 举报
回复
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Private Sub Command1_Click()

'函数返回值:
'0: 未知驱动器
'1: 软驱等可移动驱动器
'2: 固定驱动器
'3: 网络驱动器
'4: 光驱
'5: RAM驱动器
Dim DrvNum As Integer: Dim DrvVal As Long: Dim DrvCode As String
For DrvNum = 0 To 25
DrvVal = GetDriveType(Chr(DrvNum + 65) + ":") '依次对A-Z进行检测
If DrvVal = 5 Then
DrvCode = Chr$(DrvNum + 65)
CD_Check = DrvCode
End If
Next
MsgBox "光驱" & DrvCode
End Sub
射天狼 2003-08-21
  • 打赏
  • 举报
回复
加一个驱动器控件(Drive)
MsgBox Drive1.List(Drive1.ListCount - 1)

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧