| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 622 人关注过本帖
标题:[求助]如何获取光驱盘符
只看楼主 加入收藏
ywxc
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-12-5
收藏
 问题点数:0 回复次数:2 
[求助]如何获取光驱盘符

我写的程序要放在光盘上,光盘放进去后会自动运行该程序,怎么样才能用获取该光盘所在的盘符呢?应该比较简单吧?小弟谢谢先了

搜索更多相关主题的帖子: 光驱 获取 
2006-03-06 17:09
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

Option Explicit
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_CDROM = 5

Private Sub Command1_Click()
Dim i As Integer
Dim DriveStrings As String
Dim nBuffer As String * 200
Dim GetDrive As Long
Dim DriveType As Long
GetDrive = GetLogicalDriveStrings(Len(nBuffer), nBuffer)
For i = 1 To Len(nBuffer)
DriveStrings = Mid$(nBuffer, i, 1)
If DriveStrings >= "A" And DriveStrings <= "Z" Then
'Print DriveStrings
DriveType = GetDriveType(DriveStrings & ":\")
If DriveType = DRIVE_CDROM Then
MsgBox "你的CD_ROM是" & DriveStrings & "盘"
End If
End If
Next
End Sub


我的msn: myfend@
2006-03-06 18:58
xinfresh
Rank: 4
等 级:贵宾
威 望:13
帖 子:594
专家分:0
注 册:2006-1-13
收藏
得分:0 
先从工程,引用里添加一个Microsoft Script Runtime的引用,然后写:
Option Explicit
Dim fs As New FileSystemObject
Private Sub Form_Load()
Dim aDrive As Drive
For Each aDrive In fs.Drives
If aDrive.DriveType = CDRom Then
MsgBox aDrive.DriveLetter
End If
Next
End Sub
如果要判断光驱是否有盘,还要写:
If aDrive.Isready And aDrive.DriveType=CDRom Then....
.....

E-mail:xinfresh@QQ:383094053校内:http:///getuser.do?id=234719042
2006-03-06 22:06
快速回复:[求助]如何获取光驱盘符
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024627 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved