Get hardware manufacturer and system model number in VB.net?

久未见 提交于 2019-12-11 08:16:45

问题


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.

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".


回答1:


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

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 has a WMI query builder somewhere to help fnd and use the right query, though it generates very wordy code.




回答2:


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.

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.



来源:https://stackoverflow.com/questions/22797557/get-hardware-manufacturer-and-system-model-number-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!