在 VB.net 中获取硬件制造商和系统型号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22797557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get hardware manufacturer and system model number in VB.net?
提问by rabbitt
I'm trying to get the hardware manufacturer (e.g. "Dell") and the model number (e.g. "Latitude E6320") using vb.net but I'm having no luck.
我正在尝试使用 vb.net 获取硬件制造商(例如“Dell”)和型号(例如“Latitude E6320”),但我没有运气。
I've tried
我试过了
Dim opSearch As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Dim opInfo As ManagementObject
For Each opInfo In opSearch.Get()
Return opInfo("manufacturer").ToString()
Next
Though this returns "Microsoft Corporation" not "Dell".
虽然这会返回“Microsoft Corporation”而不是“Dell”。
回答by ??ssa P?ngj?rdenlarp
You are polling the wrong WMI class/hive. Of course Microsoft is the OS manufacturer; what you need is Win32_ComputerSystem:
您正在轮询错误的 WMI 类/配置单元。当然,微软是操作系统制造商;你需要的是Win32_ComputerSystem:
Imports System.Management
cs = New ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
For Each objMgmt In cs.Get
_Manufacturer = objMgmt("manufacturer").ToString()
_Model = objMgmt("model").ToString()
_SystemType = objMgmt("systemtype").ToString
_totalMem = objMgmt("totalphysicalmemory").ToString()
Next
Manufacturer will be something like "Dell, Inc", Model comes out spot on with mine, but has been known to sometimes include internal sub model identifiers. System type comes back as "x64-based PC" on mine.
制造商将类似于“戴尔公司”,模型与我的相同,但已知有时包含内部子模型标识符。我的系统类型作为“基于 x64 的 PC”返回。
MS has a WMI query builder somewhere to help fnd and use the right query, though it generates very wordy code.
MS 在某处有一个 WMI 查询生成器来帮助查找和使用正确的查询,尽管它会生成非常冗长的代码。
回答by DataCrypt
Give this a try in a console application. Just remember to add the System.Management reference to your project. You need to access the Win32_ComputerSystem not the Win32_OperatingSystem.
在控制台应用程序中尝试一下。请记住将 System.Management 引用添加到您的项目中。您需要访问 Win32_ComputerSystem 而不是 Win32_OperatingSystem。
Sub Main()
Dim objCS As Management.ManagementObjectSearcher
Dim manufacturerName As String
'objOS = New Management.ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
objCS = New Management.ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
For Each objMgmt In objCS.Get
manufacturerName = objMgmt("manufacturer").ToString()
Next
Debug.WriteLine("Manufacturer: " & manufacturerName)
End Sub
Hope it helps.
希望能帮助到你。

