Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet disk information including serial number in VB .NET
DescriptionThis example shows how to get disk information including serial number in VB .NET by using the GetVolumeInformation API function.
Keywordsdisk, serial number, GetVolumeInformation, VB.NET
CategoriesTips and Tricks
 
This example uses the GetVolumeInformation API function.
 
Private Sub Command1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Command1.Click
    Dim root As String
    Dim volume_name As String
    Dim serial_number As Integer
    Dim max_component_length As Integer
    Dim file_system_flags As Integer
    Dim file_system_name As String
    Dim pos As Integer

    root = Text1.Text
    volume_name = Space(1024)
    file_system_name = Space(1024)

    If GetVolumeInformation(root, volume_name, _
        Len(volume_name), serial_number, _
        max_component_length, file_system_flags, _
        file_system_name, Len(file_system_name)) = 0 Then
        MessageBox.Show("Error getting volume " & _
            "information.", "Error Getting Information", _
            MessageBoxButtons.OK, _
            MessageBoxIcon.Exclamation)
        Exit Sub
    End If

    pos = volume_name.IndexOf(Chr(0))
    volume_name = volume_name.Substring(0, pos)
    lblVolumeName.Text = volume_name
    lblSerialNumber.Text = serial_number.ToString
    lblMaxComponentLength.Text = _
        max_component_length.ToString

    pos = file_system_name.IndexOf(Chr(0))
    file_system_name = file_system_name.Substring(0, pos)
    lblFileSystem.Text = file_system_name

    lblFlags.Text = "&&H" & Hex$(file_system_flags)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated