问题描述
我正在尝试使用vb.net获取硬件制造商(例如"Dell")和型号(例如"Latitude E6320"),但是我没有运气.
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.
我尝试过
Dim opSearch As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Dim opInfo As ManagementObject
For Each opInfo In opSearch.Get()
Return opInfo("manufacturer").ToString()
Next
尽管这将返回"Microsoft Corporation"而不是"Dell".
Though this returns "Microsoft Corporation" not "Dell".
推荐答案
您正在轮询错误的WMI类/配置单元.当然,微软是操作系统制造商.您需要的是Win32_ComputerSystem
:
You are polling the wrong WMI class/hive. Of course Microsoft is the OS manufacturer; what you need is 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
制造商将是"Dell,Inc"之类的公司,Model随我而行,但已知有时会包含内部子模型标识符.系统类型以我的基于x64的PC"形式返回.
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.
MS在某个地方有一个WMI查询生成器,尽管它会生成非常冗长的代码,但它可以帮助fnd并使用正确的查询.
MS has a WMI query builder somewhere to help fnd and use the right query, though it generates very wordy code.
这篇关于在VB.net中获取硬件制造商和系统型号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!