且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过驱动器号获取VB.NET中的驱动器类型。

更新时间:2022-10-15 17:56:01

查看 DriveInfo类(System.IO) [ ^ ] - 它返回您需要的信息。


 Public Class Fo rm1 

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button1.Click
dfunton(TextBox1.Text)
End Sub

Private Sub GetDrivetype(ByVal drive As String)
尝试
Dim Drive_Info As System.IO.DriveInfo
Drive_Info = New System.IO.DriveInfo(drive)
Label1.Text = Drive_Info.DriveType.ToString
Catch ex As Exception
MsgBox(ex.Data)
End Try
End Sub

End Class


I am making a program that shows the type of the user inputted drive by drive letter like pen drive , local disk , cd drive, sdhd, system drive (c:).

What I have tried:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dfunton(TextBox1.Text)
    End Sub

    Private Sub dfunton(ByVal p1 As Object)
        'code for getting drive type
        Label1.Text = "drivetype"
    End Sub

End Class

Look at the DriveInfo Class (System.IO)[^] - it returns the info you need.


Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dfunton(TextBox1.Text)
    End Sub

    Private Sub GetDrivetype(ByVal drive As String)
        Try
            Dim Drive_Info As System.IO.DriveInfo
            Drive_Info = New System.IO.DriveInfo(drive)
            Label1.Text = Drive_Info.DriveType.ToString
        Catch ex As Exception
            MsgBox(ex.Data)
        End Try
    End Sub

End Class