Private Function 硬盘序列号() As String
在贞丰等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、网站设计 网站设计制作按需网站设计,公司网站建设,企业网站建设,品牌网站建设,营销型网站建设,成都外贸网站制作,贞丰网站建设费用合理。
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盘序列号 = Trim(myInfo.GetValue("SerialNumber"))
Catch
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盘序列号 = Trim(myInfo.GetValue("SerialNumber"))
Catch
硬盘序列号 = ""
End Try
End Try
End Function
只在我的电脑上试过,你试下
显卡:
Private Sub get_disp_info()
Dim i As Integer
Dim info(50) As String
Dim name(50) As String
Dim j As Integer
name(0) = "Name"
name(1) = "Caption"
name(2) = "ColorPlanes"
name(3) = "Description"
name(4) = "RefreshRate"
name(5) = "SettingID"
name(6) = "VideoMode"
name(7) = "VerticalResolution"
name(8) = "SystemPaletteEntries"
name(9) = "ReservedSystemPaletteEntries"
name(10) = "BitsPerPixel"
name(11) = "DeviceEntriesInAColorTable"
name(12) = "DeviceSpecificPens"
name(13) = "HorizontalResolution"
Dim opt As New System.Management.ManagementObjectSearcher("Select * from Win32_DisplayControllerConfiguration")
For Each obj2 As System.Management.ManagementObject In opt.Get
For j = 0 To 13
Try
info(j) = obj2(name(j))
Catch ex As Exception
info(j) = ""
End Try
Next
For i = 0 To 14
Dim newitem1 As New ListViewItem(name(i))
newitem1.SubItems.Add(info(i))
List_disp.Items.Add(newitem1)
Next
Next
End Sub
主板驱动信息:
Private Sub get_bois_info()
Dim i As Integer
Dim info(50) As String
Dim name(50) As String
Dim j As Integer
name(0) = "Name"
name(1) = "Caption"
name(2) = "SerialNumber"
name(3) = "Manufacturer"
name(4) = "Description"
name(5) = "PrimaryBIOS"
name(6) = "Version"
name(7) = "Status"
name(8) = "BuildNumber"
name(9) = "CodeSet"
name(10) = "CurrentLanguage"
name(11) = "IdentificationCode"
name(12) = "InstallableLanguages"
name(13) = "InstallDate"
name(14) = "LanguageEdition"
name(15) = "OtherTargetOS"
name(16) = "ReleaseDate"
name(17) = "SMBIOSBIOSVersion"
name(18) = "SMBIOSMajorVersion"
name(19) = "SMBIOSMinorVersion"
name(20) = "SMBIOSPresent"
name(21) = "SoftwareElementID"
name(22) = "SoftwareElementState"
name(23) = "TargetOperatingSystem"
name(24) = "ListOfLanguages"
name(25) = "BIOSVersion"
name(26) = "BiosCharacteristics"
Dim k As Integer
Dim opt As New System.Management.ManagementObjectSearcher("Select * from Win32_BIOS")
For Each obj2 As System.Management.ManagementObject In opt.Get
For j = 0 To 23
Try
info(j) = obj2(name(j))
Catch ex As Exception
info(j) = ""
End Try
Next
Try
info(24) = ""
For k = 0 To obj2(name(24)).length - 1
info(24) += obj2(name(24))(k)
Next
Catch ex As Exception
info(24) = ""
End Try
Try
info(25) = ""
For k = 0 To obj2(name(25)).length - 1
info(25) += obj2(name(25))(k)
Next
Catch ex As Exception
info(25) = ""
End Try
Try
info(26) = ""
For k = 0 To obj2(name(26)).length - 1
info(26) += obj2(name(26))(k)
Next
Catch ex As Exception
info(26) = ""
End Try
For i = 0 To 27
Dim newitem1 As New ListViewItem(name(i))
newitem1.SubItems.Add(info(i))
List_bois.Items.Add(newitem1)
Next
Next
End Sub
VB可以使用Windows管理设备(WMI)进行读取计算机硬件信息。
Dim s, System, item
Dim i As Integer
Set System = GetObject("winmgmts:").InstancesOf("Win32_ComputerSystem")
For Each item In System
‘List1.AddItem item.cputype
s = "Computer Info" vbCrLf
s = s "***********************" vbCrLf
s = s "计算机名称: " item.name vbCrLf
s = s "状态: " item.Status vbCrLf
s = s "类型: " item.SystemType vbCrLf
s = s "生产厂家: " item.Manufacturer vbCrLf
s = s "型号: " item.Model vbCrLf
s = s "内存: ~" item.totalPhysicalMemory \ 1024000 "mb" vbCrLf
s = s "域: " item.domain vbCrLf
‘s = s "工作组" item.Workgroup vbCrLf ‘获得工作组和域的选项不能同时用
s = s "当前用户: " item.username vbCrLf
s = s "启动状态" item.BootupState vbCrLf
s = s "该计算机属于" item.PrimaryOwnerName vbCrLf
s = s "系统类型" item.CreationClassName vbCrLf
s = s "计算机类类型" item.Description vbCrLf
For i = 0 To 1 ‘这里假设安装了两个系统
s = s Chr(5) "启动选项" i " :" item.SystemStartupOptions(i) _
vbCrLf
Next i
Next
Text1.Text = s
运行上面的代码后,在textBox中就可以显示计算机的信息。
在上面的代码中,程序通过GetObject("winmgmts:")获得WMI对象,然后获得下面的
Win32_ComputerSystem子项并通过访问Win32_ComputerSystem对象中的分项获得系统中的信息。
*需要说明的是,并不是所有的系统都支持WMI,在有些系统中无法显示生产厂家等信息。
Private Function 硬盘序列号() As String
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 0\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盘序列号 = Trim(myInfo.GetValue("SerialNumber"))
Catch
Try
Dim myInfo As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("HARDWARE\DEVICEMAP\Scsi\Scsi Port 1\Scsi Bus 1\Target Id 0\Logical Unit Id 0")
硬盘序列号 = Trim(myInfo.GetValue("SerialNumber"))
Catch
硬盘序列号 = ""
End Try
End Try
End Function
试下,如果返回为空,则表示失败。
在本机win8win8.1有效,不过好像在有些机器上没用。
缺少system.management.dll引用
在项目名右键--添加引用--找到system.management 确定,然后...就没然后了,就行了
strResult += 磁盘类型: System.Convert.ToInt16(disk(DriveType).ToString())End IfMsgBox(strResult)NextEnd Sub总结:在VB.NET中,用API函数可以获取硬盘信息。原来熟悉API函数VB6程序员,可以对API函数声明进行适当的更改后,进行调用。利用FSO(文件系统对象)的Scrrun.DLL,也可以获得磁盘信息。在.net Framwork中,利用WMI可以获取更多的关于机器硬件的详细信息(参考System.Management命名空间)。