通过WMI获取BIOS、主板、硬盘、CPU、网卡等电脑硬件信息,常见的源代码是高级程序设计语言如C++、Dephi,或者VBScript脚本编写的,用MASM32编程来实现相对来说要难得多,知难而上,不亦乐乎!
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;文件名:WmiInfo.asm(控制台程序)
;功能:通过WMI获取BIOS版本和序列号,主板序列号,
;硬盘序列号,CPUID,网卡MAC
;开发环境:WinXPPROSP3+MASM32v8
;作者:PurpleEndurer,2009-10-21,广西河池
;
; 源代码和EXE下载地址:
; 1、http://download.csdn.net/source/1759707; 2、http://purpleendurer.ys168.com/
;
;log
;--------------------------------------------------
;2009-10-21完成
;2009-10-20可以获取BIOS信息
;2009-10-19开始编写
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
.586
.MODELFLAT,STDCALL
OPTIONCASEMAP:NONE
INCLUDE/masm32/include/windows.inc
INCLUDE/masm32/include/kernel32.inc
INCLUDELIB/masm32/lib/kernel32.lib
INCLUDE/masm32/include/ole32.inc
INCLUDELIB/masm32/lib/ole32.lib
INCLUDE/masm32/include/user32.inc
INCLUDELIB/masm32/lib/user32.lib
INCLUDE/masm32/include/masm32.inc
INCLUDELIB/masm32/lib/masm32.lib
GetWmiInfoproto:LPWSTR,:LPSTR,:LPSTR
g_debugequ0
;locatedinObjIdl.h
EOAC_NONEEQU0
COINIT_MULTITHREADEDequ00h
;locatedinRpcDce.h
RPC_C_AUTHN_LEVEL_DEFAULTEQU0
RPC_C_IMP_LEVEL_DEFAULTEQU0
RPC_C_IMP_LEVEL_IMPERSONATEEQU3
GUID2STRUC
dd1DWORD?
dw1WORD?
dw2WORD?
db1BYTE?
db2BYTE?
db3BYTE?
db4BYTE?
db5BYTE?
db6BYTE?
db7BYTE?
db8BYTE?
GUID2ENDS
IWbemLocatorSTRUCT
lpVtblDWORD?
IWbemLocatorENDS
IWbemLocatorVtblSTRUCT
QueryInterfaceDWORD?
AddRefDWORD?
ReleaseDWORD?
ConnectServerDWORD?
IWbemLocatorVtblENDS
IWbemServicesSTRUCT
lpVtblDWORD?
IWbemServicesENDS
IWbemServicesVtblSTRUCT
QueryInterfaceDWORD?
AddRefDWORD?
ReleaseDWORD?
OpenNamespaceDWORD?
CancelAsyncCallDWORD?
QueryObjectSinkDWORD?
GetObjectDWORD?
GetObjectAsyncDWORD?
PutClassDWORD?
PutClassAsyncDWORD?
DeleteClassDWORD?
DeleteClassAsyncDWORD?
CreateClassEnumDWORD?
CreateClassEnumAsyncDWORD?
PutInstanceDWORD?
PutInstanceAsyncDWORD?
DeleteInstanceDWORD?
DeleteInstanceAsyncDWORD?
CreateInstanceEnumDWORD?
CreateInstanceEnumAsyncDWORD?
ExecQueryDWORD?
ExecQueryAsyncDWORD?
ExecNotificationQueryDWORD?
ExecNotificationQueryAsyncDWORD?
ExecMethodDWORD?
ExecMethodAsyncDWORD?
IWbemServicesVtblENDS
IEnumWbemClassObjectSTRUCT
lpVtblDWORD?
IEnumWbemClassObjectENDS
IEnumWbemClassObjectVtblSTRUCT
QueryInterfaceDWORD?
AddRefDWORD?
ReleaseDWORD?
ResetDWORD?
NextDWORD?
NextAsyncDWORD?
CloneDWORD?
SkipDWORD?
IEnumWbemClassObjectVtblENDS
IWbemClassObjectSTRUCT
lpVtblDWORD?
IWbemClassObjectENDS
IWbemClassObjectVtblSTRUCT
QueryInterfaceDWORD?
AddRefDWORD?
ReleaseDWORD?
GetQualifierSetDWORD?
GetDWORD?
PutDWORD?
DeleteDWORD?
GetNamesDWORD?
BeginEnumerationDWORD?
NextDWORD?
EndEnumerationDWORD?
GetPropertyQualifierSetDWORD?
GetObjectTextDWORD?
SpawnDerivedClassDWORD?
SpawnInstanceDWORD?
CompareToDWORD?
GetPropertyOriginDWORD?
InheritsFromDWORD?
GetMethodDWORD?
PutMethodDWORD?
DeleteMethodDWORD?
BeginMethodEnumerationDWORD?
NextMethodDWORD?
EndMethodEnumerationDWORD?
GetMethodQualifierSetDWORD?
GetMethodOriginDWORD?
IWbemClassObjectVtblENDS
SAFEARRAYBOUNDstruct
cElementsdd?;这一维有多少个元素?
lLbounddd?;它的索引从几开始?
SAFEARRAYBOUNDends
SAFEARRAYstruct
cDimsdw?;Countofdimensionsinthisarray.这个数组有几维?
fFeaturesdw?;FlagsusedbytheSafeArrayroutinesdocumentedbelow.数组有什么特性?
cbElementsdd?;Sizeofanelementofthearray.Doesnotincludesizeofpointed-todata.
;数组的每个元素有多大?
cLocksdd?;Numberoftimesthearrayhasbeenlockedwithoutcorrespondingunlock.
;这个数组被锁定过几次?
pvDatadd?;Pointertothedata.数组里的数据放在什么地方?
rgsaboundSAFEARRAYBOUND<>;Oneboundforeachdimension.真数组
SAFEARRAYends
;ssssssssssssssssssssssss
.DATA
;ssssssssssssssssssssssss
g_wszSelectWORD"S","E","L","E","C","T","","*","","F","R","O","M","",0
g_szBiosVeriondb0dh,0ah,"BIOS版本信息:",0
g_wszWin32_BIOSword"W","i","n","3","2","_","B","I","O","S",0
g_wszBIOSVerstionword"B","I","O","S","V","e","r","s","i","o","n",0
g_szBiosSerialNumberdb0dh,0ah,"BIOS序列号:",0
g_szHDDSerialNumdb0dh,0ah,"硬盘序列号:",0
g_wszWin32_PhysicalMediaword"W","i","n","3","2","_"
WORD"P","h","y","s","i","c","a","l","M","e","d","i","a",0
g_wszSerialNumberword"S","e","r","i","a","l","N","u","m","b","e","r",0
g_szBaseBoardSerialNumdb0dh,0ah,"主板序列号:",0
g_wszWin32_BaseBoardword"W","i","n","3","2","_","B","a","s","e","B","o","a","r","d",0
g_szCpuIddb0dh,0ah,"CPUID:",0
g_wszWin32_Processorword"W","i","n","3","2","_","P","r","o","c","e","s","s","o","r",0
g_wszProcessorIdword"P","r","o","c","e","s","s","o","r","I","d",0
g_szNidMacdb0dh,0ah,"网卡MAC:",0
g_wszWin32_NetworkAdapterword"W","i","n","3","2","_"
WORD"N","e","t","w","o","r","k","A","d","a","p","t","e","r",0
g_wszMACAddressword"M","A","C","A","d","d","r","e","s","s",0
g_wszNameSpaceword"r","o","o","t","/","c","i","m","v","2",0
g_wszQueryLanguageword"W","Q","L",0
g_szAppInfodb"通过WMI获取硬件信息",0dh,0ah
db"作者:PurpleEndurer,2009-10-21,广西河池",0dh,0ah,0
g_szPerSCrdb"%S"
g_szCrLfdb0dh,0ah,0
g_szFaildb"Fail",0
;locatedinWbemCli.h
WBEM_FLAG_CONNECT_USE_MAX_WAITEQU80h
WBEM_FLAG_FORWARD_ONLYEQU20h
WBEM_INFINITEEQU-1
WBEM_E_INVALID_QUERYEQU80041017h
WBEM_E_INVALID_QUERY_TYPEEQU80041018h
IID_IWbemLocatorGUID2<0dc12a687h,0737fh,011cfh,088h,04dh,000h,0aah,000h,04bh,02eh,024h>
IID_IEnumWbemClassObjectGUID2<027947e1h,0d731h,011ceh,0a3h,057h,000h,000h,000h,000h,000h,001h>
IID_IWbemClassObjectGUID2<0dc12a681h,0737fh,011cfh,088h,04dh,000h,0aah,000h,04bh,02eh,024h>
;locatedinWbemProv.h
CLSID_WbemAdministrativeLocatorGUID2<0cb8555cch,09128h,011d1h,0adh,09bh,000h,0c0h,04fh,0d8h,0fdh,0ffh>
locatorIWbemLocator<>
serviceIWbemServices<>
enumeratorIEnumWbemClassObject<>
processorIWbemClassObject<>
retCountDWORD?
var_valDWORD?
DWORD?
DWORD?
DWORD?
wszQueryWORD256dup(?)
g_szBuf512byte512dup(?)
;ssssssssssssssssssssssss
.CODE
;ssssssssssssssssssssssss
start:
invokeCoInitializeEx,NULL,COINIT_MULTITHREADED
invokeCoInitializeSecurity,NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_DEFAULT,/
RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL
invokeCoCreateInstance,ADDRCLSID_WbemAdministrativeLocator,NULL,/
CLSCTX_INPROC_SERVER,ADDRIID_IWbemLocator,ADDRlocator
invokeStdOut,ADDRg_szAppInfo
invokeStdOut,ADDRg_szBiosVerion
movbyteptrg_szBuf512,NULL
invokeGetWmiInfo,ADDRg_wszWin32_BIOS,ADDRg_wszBIOSVerstion,ADDRg_szBuf512
.ifbyteptrg_szBuf512!=NULL
invokeStdOut,ADDRg_szBuf512
.else
invokeStdOut,ADDRg_szFail
.endif
invokeStdOut,ADDRg_szBiosSerialNumber
movbyteptrg_szBuf512,NULL
invokeGetWmiInfo,ADDRg_wszWin32_BIOS,ADDRg_wszSerialNumber,ADDRg_szBuf512
.ifbyteptrg_szBuf512!=NULL
invokeStdOut,ADDRg_szBuf512
.else
invokeStdOut,ADDRg_szFail
.endif
invokeStdOut,ADDRg_szHDDSerialNum
movbyteptrg_szBuf512,NULL
invokeGetWmiInfo,ADDRg_wszWin32_PhysicalMedia,ADDRg_wszSerialNumber,ADDRg_szBuf512
.ifbyteptrg_szBuf512!=NULL
invokeStdOut,ADDRg_szBuf512
.else
invokeStdOut,ADDRg_szFail
.endif
invokeStdOut,ADDRg_szBaseBoardSerialNum
movbyteptrg_szBuf512,NULL
invokeGetWmiInfo,ADDRg_wszWin32_BaseBoard,ADDRg_wszSerialNumber,ADDRg_szBuf512
.ifbyteptrg_szBuf512!=NULL
invokeStdOut,ADDRg_szBuf512
.else
invokeStdOut,ADDRg_szFail
.endif
invokeStdOut,ADDRg_szCpuId
movbyteptrg_szBuf512,NULL
invokeGetWmiInfo,ADDRg_wszWin32_Processor,ADDRg_wszProcessorId,ADDRg_szBuf512
.ifbyteptrg_szBuf512!=NULL
invokeStdOut,ADDRg_szBuf512
.else
invokeStdOut,ADDRg_szFail
.endif
invokeStdOut,ADDRg_szNidMac
movbyteptrg_szBuf512,NULL
invokeGetWmiInfo,ADDRg_wszWin32_NetworkAdapter,ADDRg_wszMACAddress,ADDRg_szBuf512
.ifbyteptrg_szBuf512!=NULL
invokeStdOut,ADDRg_szBuf512
.else
invokeStdOut,ADDRg_szFail
.endif
invokeCoUninitialize
invokeExitProcess,0
GetWmiInfoproclpwszType:LPWSTR,lpwszItem:LPSTR,lpszBuf:LPSTR
LOCALwszbuf[256]:word
invokelstrcpyW,ADDRwszQuery,ADDRg_wszSelect
invokelstrcatW,ADDRwszQuery,lpwszType
movesi,locator
lodsd
pushOFFSETservice
pushNULL
pushNULL
pushWBEM_FLAG_CONNECT_USE_MAX_WAIT
pushNULL
pushNULL
pushNULL
pushOFFSETg_wszNameSpace
pushDWORDPTR[locator]
callDWORDPTR[eax][IWbemLocatorVtbl.ConnectServer]
movesi,service
lodsd
pushOFFSETenumerator
pushNULL
pushWBEM_FLAG_FORWARD_ONLY
pushOFFSETwszQuery
pushOFFSETg_wszQueryLanguage
pushDWORDPTR[service]
callDWORDPTR[eax][IWbemServicesVtbl.ExecQuery]
movesi,enumerator
lodsd
pushOFFSETretCount
pushOFFSETprocessor
pushTRUE
pushWBEM_INFINITE
pushDWORDPTR[enumerator]
callDWORDPTR[eax][IEnumWbemClassObjectVtbl.Next]
movesi,processor
lodsd
pushNULL
pushNULL
pushOFFSETvar_val
push0
pushlpwszItem
pushDWORDPTR[processor]
callDWORDPTR[eax][IWbemClassObjectVtbl.Get]
ifg_debugeq1
jmp@F
g_sz1db0dh,0ah,"eax=%d,ecx=%x,esi=%x,edi=%x",0dh,0ah,0
@@:
movesi,[var_val]
movedi,[var_val+4]
movecx,[var_val+8]
moveax,[var_val+12]
pushad
invokewsprintf,ADDRwszbuf,ADDRg_sz1,eax,ecx,esi,edi
invokeStdOut,ADDRwszbuf
popad
endif;g_debugeq1
moveax,[var_val]
testeax,VT_BSTR
.if!ZERO?
testeax,VT_ARRAY
.IF!ZERO?
movecx,[var_val+8]
movesi,[ecx].SAFEARRAY.pvData
movedi,[ecx].SAFEARRAY.rgsabound.cElements
ifg_debugeq1
movzxeax,[ecx].SAFEARRAY.cDims
movecx,[ecx].SAFEARRAY.rgsabound.lLbound
pushad
invokewsprintf,ADDRwszbuf,ADDRg_sz1,eax,ecx,esi,edi
invokeStdOut,ADDRwszbuf
popad
endif;g_debugeq1
.repeat;whileedi
pushesi
pushedi
movecx,[esi]
invokewsprintf,ADDRwszbuf,ADDRg_szPerSCr,ecx
invokelstrcat,lpszBuf,ADDRwszbuf
popedi
popesi
decedi
addesi,4
.untiledi==0;endw
.ELSE
invokewsprintf,ADDRwszbuf,ADDRg_szPerSCr,[var_val+8]
invokelstrcat,lpszBuf,ADDRwszbuf
.ENDIF
.endif
ret
GetWmiInfoendp
;======================================================
ENDstart