News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Computer Make and Model identifier

Started by Shooter, March 20, 2011, 02:33:05 PM

Previous topic - Next topic

Shooter

Is there an API that is simple to use to identify the computer's make and model, or perhaps a place in the system registry (consistent for all Windows versions)?

Thanks,
-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

donkey

That's done using WMI's Win32_ComputerSystem Class and though it is straight forward, it is not "simple" to use.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Shooter

Quote from: donkey on March 20, 2011, 02:47:27 PM
That's done using WMI's Win32_ComputerSystem Class and though it is straight forward, it is not "simple" to use.

Yeah, I saw that earlier and was blown away. It certainly don't look 'simple'.  :'(
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

donkey

You can query the registry or  look for an oeminfo.ini file, but they can be altered so they're unreliable or you can go the complicated route of writing a driver to query the SMBIOS directly. Its those or WMI.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Shooter

Quote from: donkey on March 20, 2011, 04:16:18 PM
You can query the registry or  look for an oeminfo.ini file, but they can be altered so they're unreliable or you can go the complicated route of writing a driver to query the SMBIOS directly. Its those or WMI.

Since my program is dependent on the model I guess I'm gonna have to go the long route.  I've never dealt directly with a class like that before, so I guess I might be callin' on some help in the future on this one, particularly in converting it to MASM code. :(
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

Magnum

For HP Computers, there are a number of registry entries that contain the make and model.

Have a great day,
                         Andy

Shooter

Quote from: Magnum on March 20, 2011, 06:42:27 PM
For HP Computers, there are a number of registry entries that contain the make and model.

The same holds true for SOME Dell models, but not all.
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

donkey

#7
Seriously, don't dick around with the registry, it can be changed by any user who can type RegEdit and use the FIND function. If you want to do a professional application then use the right interfaces and in this case that means using WMI to read the SMBIOS. Here's a quick demo of getting the manufacturer, you can always add anything else you want from the Win32_ComputerSystem Class object. Note that this is COM so be sure to call CoInitialize.

// Headers available at
// http://www.quickersoft.com/donkey/index.html

// NOTE: INCLUDE Environment variable must be set to headers path

#DEFINE WINVER NTDDI_WIN7
#DEFINE FILTERAPI
#DEFINE LINKFILES

#include "WINDOWS.H"
#include "macros.h"
#include "wbemcli.h"

DATA SECTION
// Classes
CLSID_WbemLocator GUID GUID_CLSID_WbemLocator

// Interfaces
IID_IUnknown GUID GUID_IID_IUnknown
IID_IWbemLocator GUID GUID_IID_IWbemLocator
IID_IWbemServices GUID GUID_IID_IWbemServices

// Pointers >> in X64 builds do not store any pointers in LOCAL data !
pNameSpace PTR ?
pWbemLocator PTR ?
pUnk PTR ?
pObj PTR ?
pEnum PTR ?

// Results
szManufacturer CHAR 256 DUP (?)
szModel CHAR 256 DUP (?)

CODE SECTION

invoke CoInitialize,NULL

invoke GetManufacturer,offset szManufacturer,offset szModel

invoke MessageBox,NULL,offset szModel,offset szManufacturer,NULL

invoke CoUninitialize

invoke ExitProcess,0

GetManufacturer FRAME pManufacturer, pModel
LOCAL hres :%HANDLE
LOCAL bstrNameSpace :%PTR
LOCAL variant :%PTR

// Connect to the desired namespace
invoke SysAllocString,L"\\.\root\cimv2"
mov [bstrNameSpace], eax

invoke CoInitializeSecurity, 0,-1,0,0,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE,0
mov [hres],eax

invoke CoCreateInstance,offset CLSID_WbemLocator,NULL,CLSCTX_INPROC_SERVER,offset IID_IWbemLocator, offset pWbemLocator
test eax,eax
jnz >>.EXIT

CoInvoke(pWbemLocator,IWbemLocator.ConnectServer,[bstrNameSpace],0,0,0,0,0,0,offset pNameSpace)
test eax,eax
jnz >>.EXIT1
CoInvoke(pNameSpace,IWbemServices.IUnknown.QueryInterface,offset IID_IUnknown,offset pUnk)
test eax,eax

// Set the security for our proxy
invoke CoSetProxyBlanket,[pNameSpace],RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,0,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE
invoke CoSetProxyBlanket,[pUnk],RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,0,RPC_C_AUTHN_LEVEL_DEFAULT,RPC_C_IMP_LEVEL_IMPERSONATE,0,EOAC_NONE
CoInvoke(pUnk,Unknown.Release)

// Execute the query, just pull all of the information
CoInvoke(pNameSpace,IWbemServices.ExecQuery, L"WQL", L'Select * from Win32_ComputerSystem',WBEM_FLAG_RETURN_IMMEDIATELY,NULL,offset pEnum)
test eax,eax
jnz >>.EXIT2

// Step the enumeration through the class object
CoInvoke(pEnum,IEnumWbemClassObject.Next,WBEM_INFINITE,1,offset pObj,offset hres)
test eax,eax
jnz >.EXIT3

// Get the information we want
CoInvoke(pObj,IWbemClassObject.Get,L"Manufacturer",0,offset variant,0,0)
test eax,eax
jnz >.EXIT4
// The information is in UNICODE so convert it
invoke WideCharToMultiByte,CP_ACP,NULL,[variant+8],-1,[pManufacturer],256,NULL,NULL
invoke VariantClear,offset variant

CoInvoke(pObj,IWbemClassObject.Get,L"Model",0,offset variant,0,0)
test eax,eax
jnz >.EXIT4
// The information is in UNICODE so convert it
invoke WideCharToMultiByte,CP_ACP,NULL,[variant+8],-1,[pModel],256,NULL,NULL
invoke VariantClear,offset variant

.EXIT4
CoInvoke(pObj,IWbemClassObject.Release)
.EXIT3
CoInvoke(pEnum,IEnumWbemClassObject.Release)
.EXIT2
CoInvoke(pNameSpace,IWbemServices.Release)
.EXIT1
CoInvoke(pWbemLocator,IWbemLocator.Release)
.EXIT
invoke SysFreeString,[bstrNameSpace]
ret
endf


PS don't even bother to ask me to translate this, I program in GoAsm and on occasion I will translate things to MASM but this is too much work since MASM does not have intrinsic inline strings or UNICODE support.

edit: added VariantClear to free up resources.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

donkey

Forgot to attach the project, here it is with source and executable:

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

hutch--

Edgar,

It identifies my Intel board fine.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

donkey

Thanks Steve,

I neglected to call VariantClear after each of the WideCharToMultiByte calls:

invoke WideCharToMultiByte,CP_ACP,NULL,[variant+8],-1,[pModel],256,NULL,NULL
invoke VariantClear,offset variant


It should be called to free the variants resources.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Shooter

Edgar,
It identified my Dell Latitude D600 just fine. I'll try it at work to see how it does there too.

Thanks a ton. Now I just gotta integrate it into my project somehow. I'm not at all familiar with the Windows COM objects, and going from GoASM to MASM might be a bit of a challenge for this newby, but I think I can work with this code you provided. Handy little code too.

-Shooter
Never use direct references to anything ever. Bury everything in
macros. Bury the macros in include files. Reference those include
files indirectly from other include files. Use macros to reference
those include files.

sinsi

Mine says "To Be Filled By O.E.M."  :lol

To be fair, I think the BIOS setup tells me the same.
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

mine reports "VGC-RB42G" which is correct however, you'd have to know that was a Sony model number

donkey

Quote from: dedndave on March 21, 2011, 01:53:21 PM
mine reports "VGC-RB42G" which is correct however, you'd have to know that was a Sony model number

Hi Dave,

No "Sony" as the MessageBox title ? I would have thought they would have adhered to the specs.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable