Jump to content

saber informacoes do disco rigido


rui_fernandes
 Share

Recommended Posts

Ok, toma lá a "papinha" já pronta  👍

Imports System.Management

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim drives As New ArrayList

        Dim query As New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")

        For Each wmiDrive As ManagementObject In query.Get()
            Dim info As New DriveInfo
            info.Model = wmiDrive("Model").ToString()
            info.Type = wmiDrive("InterfaceType").ToString()
            drives.Add(info)
        Next

        query = New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")

        Dim i As Integer = 0
        For Each wmiDrive As ManagementObject In query.Get()
            ' Get the hard drive from collection using index.
            Dim info As DriveInfo = CType(drives(i), DriveInfo)
            ' Get the hardware serial number.
            If wmiDrive("SerialNumber") Is Nothing Then
                info.SerialNumber = "None"
            Else
                info.SerialNumber = wmiDrive("SerialNumber").ToString()
            End If
            i += 1
        Next

        ' Mostra a informação do disco
        For Each info As DriveInfo In drives
            Dim sBuilder As New System.Text.StringBuilder
            sBuilder.AppendLine("Model:" + info.Model)
            sBuilder.AppendLine("Type:" + info.Type)
            sBuilder.AppendLine("Serial No.:" + info.SerialNumber)
            MessageBox.Show(sBuilder.ToString)
        Next

    End Sub
End Class


Class DriveInfo
    Private _model As String
    Private _type As String
    Private _serialNumber As String

    Public Property Model() As String
        Get
            Return _model
        End Get
        Set(ByVal Value As String)
            _model = Value
        End Set
    End Property

    Public Property Type() As String
        Get
            Return _type
        End Get
        Set(ByVal Value As String)
            _type = Value
        End Set
    End Property

    Public Property SerialNumber() As String
        Get
            Return _serialNumber
        End Get
        Set(ByVal Value As String)
            _serialNumber = Value
        End Set
    End Property

End Class
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.