inoviaさんが紹介している hiro氏 の WMImoduleを利用した少し詳細なサンプルです。
CPU関連は、Win32_Processorというクラスを利用しており、プロパティは全部48個あります。
取得には、少し時間がかかるのが難点です。VBScriptにして、一旦、外部に書き出し、cscriptで
実行させてコンソールリダイレクトで結果を取得する方法の方が若干ですが、速度的には速いです。
サンプルスクリプトは少し長いですが、ご勘弁を・・・・
;***** CPU関連情報の取得 (wmiopt65.hsp) *****
;*****************************************************************************
; WMImodule
; 「HSPメモ帳(全然更新しないブログ)」 作成者 : hiro氏
; URL : http://blog.goo.ne.jp/hiro239415/e/b0fb4ec697b8dbb34645f9600f4fac9a
;
;*****************************************************************************
#module WMImodule
#uselib "ole32.dll"
#func CoSetProxyBlanket "CoSetProxyBlanket" comobj,int,int,int,int,int,int,int
#define IID_IWbemLocator "{dc12a687-737f-11cf-884d-00aa004b2e24}"
#define CLSID_WbemLocator "{4590f811-1d3a-11d0-891f-00aa004b2e24}"
#usecom IWbemLocator IID_IWbemLocator CLSID_WbemLocator
#comfunc WbemLoc_ConnectServer 3 wstr,int,int,int,int,int,int,var
#define IID_IWbemServices "{9556dc99-828c-11cf-a37e-00aa003240c7}"
#define CLSID_WbemServices "{D68AF00A-29cb-43fa-8504-ce99a996d9ea}"
#usecom IWbemServices IID_IWbemServices CLSID_WbemServices
#comfunc WbemSvc_ExecQuery 20 wstr,wstr,int,int,var
#define IID_IEnumWbemClassObject "{027947e1-d731-11ce-a357-000000000001}"
#define CLSID_EnumWbemClassObject "{1b1cad8c-2dab-11d2-b604-00104b703efd}"
#usecom IEnumWbemClassObject IID_IEnumWbemClassObject CLSID_EnumWbemClassObject
#comfunc EnumWbem_Reset 3
#comfunc EnumWbem_Next 4 int,int,var,var
#define IID_IWbemClassObject "{dc12a681-737f-11cf-884d-00aa004b2e24}"
#define CLSID_WbemClassObject "{9A653086-174F-11d2-B5F9-00104B703EFD}"
#usecom IWbemClassObject IID_IWbemClassObject IID_IWbemClassObject
#comfunc WbemClsObj_Get 4 wstr,int,var,int,int
#deffunc GetWMIData array data,str query,str type
newcom pLoc, IWbemLocator
if( stat == 0 ){
WbemLoc_ConnectServer pLoc, "root\\cimv2", 0, 0, 0, 0, 0, 0, ppSvc
if( stat == 0 ){
newcom pSvc, IWbemServices, -1, ppSvc
if( stat == 0 ){
CoSetProxyBlanket pSvc,10,0,0,3,3,0,0
if( stat == 0 ){
WbemSvc_ExecQuery pSvc, "WQL", query, 48, 0, ppEnum
if( stat == 0 ){
newcom pEnum, IEnumWbemClassObject, -1, ppEnum
if( stat == 0 ){
dimtype vRet, vartype("variant")
repeat
EnumWbem_Next pEnum, -1, 1, ppclsObj, uReturn
if( uReturn == 0 ) : c = cnt : break
newcom pclsObj, IWbemClassObject, -1, ppclsObj
if( stat == 0 ){
WbemClsObj_Get pclsObj, type, 0, vRet, 0, 0
data(cnt) = vRet("value")
delcom pclsObj
}
loop
delcom pEnum
}
}
}
delcom pSvc
}
}
delcom pLoc
}
return c
#global
#module
#uselib "user32.dll"
#cfunc GetForegroundWindow "GetForegroundWindow"
#cfunc GetWindow "GetWindow" int,int
#define GW_CHILD $00000005
#define WM_SETTEXT $0000000C
#deffunc bufcpypad var prm1
;***************************************************
; prm1 : バッファ文字列用変数
;***************************************************
;***** notepad.exeを起動してハンドルを取得する *****
exec "notepad.exe"
nhwnd=GetForegroundWindow() : if nhwnd==0 : return -1
nhwnd=GetWindow(nhwnd,GW_CHILD) : if nhwnd==0 : return -1
;***** notepadにバッファ文字列を送信(複写)する *****
sendmsg nhwnd,WM_SETTEXT,0,varptr(prm1)
return 0
#global
#uselib "gdi32.dll"
#cfunc GetStockObject "GetStockObject" int
#func SetTextColor "SetTextColor" int,int
#func SetBkColor "SetBkColor" int,int
#func DeleteObject "DeleteObject" sptr
#define WM_CTLCOLOREDIT $00000133
#define BLACK_BRUSH $00000004
#define EM_SETMARGINS $000000D3
#define EC_LEFTMARGIN $00000001
#define EC_RIGHTMARGIN $00000002
#define ctype RGB(%1,%2,%3) (%1|(%2<<8)|(%3<<16))
#define ctype MAKELONG(%1,%2) (%1&$ffff|(%2<<16))
;***********************************************************
; ・参照サイト
; 「VBS for Windows Management Instrumentation」
; URL : http://www.geocities.jp/maru3128/wmi.html
; 「WMI Fun !!」WMI Library
; URL : http://www.wmifun.net/library/
;
; ExecQuery : Select * From Win32_Processor
; Class : Win32_Processor
; Property : Description,Name,Manufacturer,Architecture
; CurrentClockSpeed,CurrentVoltage,ExtClock
; MaxClockSpeed,L2CacheSize,ProcessorId
; Revision,SocketDesignation,Stepping
; Version
; Sample : CPU関連情報の取得
;***********************************************************
onexit goto *owari
sdim data0, 64 : sdim data1, 64 : sdim data2, 64 : sdim data3, 64
sdim data4, 64 : sdim data5, 64 : sdim data6, 64 : sdim data7, 64
sdim data8, 64 : sdim data9, 64 : sdim data10,64 : sdim data11,64
sdim data12,64 : sdim data13,64
mbData = ""
title "データ取得中! しばらくお待ちください。。。。。"
font "MS ゴシック",12 : objmode 2
mesbox mbData, ginfo_winx, ginfo_winy-40,5
sendmsg objinfo(0,2), EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN,MAKELONG(5,5)
hedit=objinfo(0,2)
hBrush=GetStockObject(BLACK_BRUSH)
oncmd gosub *OnWM_CTLCOLOREDIT, WM_CTLCOLOREDIT
pos ginfo_winx-90, ginfo_winy-34
objsize 80,26 : button "コピー",*dCopy
GetWMIData data0, "Select * From Win32_Processor", "Description"
GetWMIData data1, "Select * From Win32_Processor", "Name"
GetWMIData data2, "Select * From Win32_Processor", "Manufacturer"
GetWMIData data3, "Select * From Win32_Processor", "Architecture"
GetWMIData data4, "Select * From Win32_Processor", "CurrentClockSpeed"
GetWMIData data5, "Select * From Win32_Processor", "CurrentVoltage"
GetWMIData data6, "Select * From Win32_Processor", "ExtClock"
GetWMIData data7, "Select * From Win32_Processor", "MaxClockSpeed"
GetWMIData data8, "Select * From Win32_Processor", "L2CacheSize"
GetWMIData data9, "Select * From Win32_Processor", "ProcessorId"
GetWMIData data10,"Select * From Win32_Processor", "Revision"
GetWMIData data11,"Select * From Win32_Processor", "SocketDesignation"
GetWMIData data12,"Select * From Win32_Processor", "Stepping"
GetWMIData data13,"Select * From Win32_Processor", "Version"
gdata=stat
title ""+gdata+"個のデータを取得しました。"
if gdata=0 : mbData = "データを取得できませんでした。" : objprm 0, mbData : stop
repeat gdata
await
;***** CPUのモデル・ステップ *****
mbData += "Description : " + data0(cnt) + "\n"
;***** CPUの名前 *****
mbData += "Name : " + data1(cnt) + "\n"
;***** CPUの製造元 *****
mbData += "Manufacturer : " + data2(cnt) + "\n"
;***** CPUアーキテクチャ *****
switch int(data3(cnt))
case 0 : mbData +="Architecture : x86" + "\n" : swbreak
case 1 : mbData +="Architecture : MIPS" + "\n" : swbreak
case 2 : mbData +="Architecture : Alpha" + "\n" : swbreak
case 3 : mbData +="Architecture : PowerPC" + "\n" : swbreak
case 6 : mbData +="Architecture : ia64" + "\n" : swbreak
default: mbData +="不明 -> " + data3(cnt) + "\n"
swbreak
swend
;***** CPUの現在の周波数 *****
mbData += "CurrentClockSpeed: " + data4(cnt) + "MHz\n"
;***** CPUの現在の電圧 *****
mbData += "CurrentVoltage : " + data5(cnt) + "V\n"
;***** CPUバスクロック *****
mbData += "ExtClock : " + data6(cnt) + "MHz\n"
;***** CPU最大周波数 *****
mbData += "MaxClockSpeed : " + data7(cnt) + "MHz\n"
;***** CPUキャッシュサイズ *****
mbData += "L2CacheSize : " + data8(cnt) + "\n"
;***** CPUID *****
mbData += "ProcessorId : " + data9(cnt) + "\n"
;***** CPUレビジョン *****
mbData += "Revision : " + data10(cnt) + "\n"
;***** ソケットタイプ *****
mbData += "SocketDesignation: " + data11(cnt) + "\n"
;***** CPUステップ *****
mbData += "Stepping : " + data12(cnt) + "\n"
;***** CPUバージョン *****
mbData += "Version : " + data13(cnt) + "\n"
loop
objprm 0, mbData
stop
*dCopy
;***** メモ帳に内容複写 *****
bufcpypad mbData
stop
*OnWM_CTLCOLOREDIT
;***** mesboxの背景色と文字色を変更 *****
if ( lParam == hedit ) {
SetTextColor wParam, RGB(255,255,255)
SetBkColor wParam, RGB(0,0,0)
return (hBrush)
}
return
*owari
DeleteObject hBrush
end