VB.Net/Windows System/Management

Материал из VB Эксперт
Перейти к: навигация, поиск

Get Drive Serial

  
Public Class MainClass
    Public Shared Function GetDriveSerial(ByVal DriveLetter As String) As String
        Dim strSelectText As String = "Win32_logicaldisk="" & DriveLetter & """
        Dim objMO As New System.Management.ManagementObject(strSelectText)
        objMO.Get()
        Return CType(objMO.Properties("VolumeSerialNumber").Value, String)
    End Function
    Public Shared Sub Main
        System.Console.WriteLine(GetDriveSerial("C:"))
    End Sub
End Class