当前位置:首页 > 编程学习 > VB获取光驱盘符

VB获取光驱盘符

编程学习2007-04-2956280

VB获取光驱盘符

Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" _
(ByVal nDrive As String) As Long
'GetLogicalDriveStrings-->获取一个字串,其中包含了当前所有逻辑驱动器的根驱动器路径
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
       
Private Sub Command1_Click()
    Dim rtn As String
    Dim AllDrives As String
    Dim JustOneDrive As String
    AllDrives = Space$(64) '设置缓冲
    rtn = GetLogicalDriveStrings(Len(AllDrives), AllDrives) '调用函数得到包含所有驱动器的字符串
    AllDrives = Left(AllDrives, rtn)
    Do
        rtn = InStr(AllDrives, Chr(0))
        If rtn Then '若有的话
            JustOneDrive = Left(AllDrives, rtn)
            AllDrives = Mid(AllDrives, rtn + 1, Len(AllDrives))
            rtn = GetDriveType(JustOneDrive) '检查驱动器类型
            If rtn = DRIVE_CDROM Then '是CD-ROM
                Label1.Caption = Left(UCase(JustOneDrive), 2) '给label1
                Exit Do
            End If
        End If
    Loop Until AllDrives = "" Or rtn = DRIVE_CDROM
    Command1.Enabled = False
    If Label1.Caption = "" Then Label1.Caption = "没有发现光驱!"
End Sub


扫描二维码推送至手机访问。

版权声明:本文由海阔天空发布,如需转载请注明出处。

本文链接:https://apull.net/html/20070429182.html

标签: 编程技术VB
分享给朋友:

相关文章

 C++ string类常用函数

C++ string类常用函数

string类的构造函数:string(const char *s);    //用c字符串s初始化 string(int n,char  c);     //用n个字符c初始化此外,string类还支持默认构造函数和复制构造函数,如string s1;string  s2="hello";都是正确的写法。...

ASP六大对象介绍

ASP六大对象介绍

Application对象 Application对象是个应用程序级的对象,用来在所有用户间共享信息,并可以在Web应用程序运行期间持久地保持数据。 Application的属性:  方法如下: Application对象没有内置的属性,但是我们可以自行创建其属性。 <% Application("属性名")=值 %>    其实大部分Application变量都 存放在Contents集合中,当你创建一个新的Application变量时,其实...

ASP错误提示大全

ASP错误提示大全

Microsoft VBScript 语法错误(0×800A03E9)–>内存不足Microsoft VBScript 语法错误(0×800A03EA)–>语法错误Microsoft VBScript 语法错误(0×800A03EB)–>缺少’:’Microsoft VBScript 语法错误(0×800A03ED)–>缺少’(’Mi...

[转].NET实现中英文验证码

[转].NET实现中英文验证码

最终效果如图:  CheckCode.aspx.cs代码如下protected void Page_Load(object sender, EventArgs e) { //获取GB2312编码页(表) /**//** * 生成中文验证验码所要使用的方法 * 注,生成中文验证码时要改变一下生成验证码图片的宽度 * var imageCode = new System.Drawing.Bitmap((int)Math....