vb.net如何获取硬盘的序列号
vb.net如何获取硬盘的序列号,注意不是盘符的,谢谢
[解决办法]
http://www.docin.com/p-374146154.html
[解决办法]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '需要引用 Imports Scripting ListBox1.Items.Clear() Try Dim cmicWmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") Dim Uint32 As Long = 0 For Each cmicWmiObj As Management.ManagementObject In cmicWmi.Get Uint32 = cmicWmiObj("signature") '必须要用 signature ListBox1.Items.Add(Uint32.ToString) Next TextBox1.Text = Uint32.ToString Catch ex As Exception MsgBox(ex.ToString) End TryEnd Sub
[解决办法]
这种东西网上一搜一大把,复杂么?别人都封装好了。你拿来直接粘贴用就行了。这都觉得复杂,的确过分了有点。
Dim cmicWmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive") Dim Uint32 As UInt32For Each cmicWmiObj As ManagementObject In cmicWmi.GetUint32 = cmicWmiObj("signature")NextTextBox1.Text = Uint32.ToString'获得CPU序列号Dim Wmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_Processor")Dim Uint32 As StringFor Each WmiObj As ManagementObject In Wmi.GetUint32 = WmiObj("ProcessorId")NextTextBox1.Text = Uint32'获得硬盘总容量Dim Wmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")Dim Uint64 As UInt64For Each WmiObj As ManagementObject In Wmi.GetUint64 = WmiObj("size")NextTextBox1.Text = Uint64.ToString