vb.net中CD驱动器的驱动器号 [英] Drive letter of CD Drive in vb.net
本文介绍了vb.net中CD驱动器的驱动器号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码来获取计算机中的驱动器号列表.我想从此列表中获取CD驱动器的驱动器号.请告知如何检查.
我用来获取列表的代码如下:
表单加载事件
Hi,
I am using following code to get Drive letter list in my computer. I want to get the drive letter of CD Drive from this list. Please advise how to check it.
The code I am using to get list is as below:
In form load event
cmbDrives.DropDownStyle = ComboBoxStyle.DropDownList
Dim sDrive As String, sDrives() As String
sDrives = ListAllDrives()
For Each sDrive In sDrives
Next
cmbDrives.Items.AddRange(ListAllDrives())
Public Function ListAllDrives() As String()
Dim arDrives() As String
arDrives = IO.Directory.GetLogicalDrives()
Return arDrives
End Function
谢谢
Furqan
[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]
Thanks
Furqan
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
推荐答案
<pre lang="vb">
Dim CDPath as String
Private Sub Form_Load()
Dim fso As New Scripting.FileSystemObject
Dim drv As Drive
For Each drv In fso.Drives
If drv.DriveType = CDRom Then
CDPath = drv.Path
Exit For
End If
Next drv
Set drv = Nothing
Set fso = Nothing
End Sub
尝试:
Public Enum DriveType As Integer
Unknown = 0
NoRoot = 1
Removable = 2
Localdisk = 3
Network = 4
CD = 5
RAMDrive = 6
End Enum
<DllImport("kernel32.dll", CharSet := CharSet.Auto)> _
Public Shared Function GetDriveType(lpRootPathName As String) As Integer
End Function
Private Shared Sub Main(args As String())
Console.WriteLine("Started")
Dim drives As String() = Directory.GetLogicalDrives()
For Each drive As String In drives
Dim type As DriveType = CType(GetDriveType(drive), DriveType)
Console.WriteLine(drive & " is a " & type.ToString())
Next
Console.WriteLine("Stopped")
Console.ReadLine()
End Sub
这篇关于vb.net中CD驱动器的驱动器号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文