Jump to Real's How-to Main page

Get CPU or other hardware/software infos

Send Query to Windows using the WMI package.

To know more about your CPU

ref : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_processor.asp

class Win32_Processor : CIM_Processor
{
  uint16 AddressWidth;
  uint16 Architecture;
  uint16 Availability;
  string Caption;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  uint16 CpuStatus;
  string CreationClassName;
  uint32 CurrentClockSpeed;
  uint16 CurrentVoltage;
  uint16 DataWidth;
  string Description;
  string DeviceID;
  boolean ErrorCleared;
  string ErrorDescription;
  uint32 ExtClock;
  uint16 Family;
  datetime InstallDate;
  uint32 L2CacheSize;
  uint32 L2CacheSpeed;
  uint32 LastErrorCode;
  uint16 Level;
  uint16 LoadPercentage;
  string Manufacturer;
  uint32 MaxClockSpeed;
  string Name;
  string OtherFamilyDescription;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  string ProcessorId;
  uint16 ProcessorType;
  uint16 Revision;
  string Role;
  string SocketDesignation;
  string Status;
  uint16 StatusInfo;
  string Stepping;
  string SystemCreationClassName;
  string SystemName;
  string UniqueId;
  uint16 UpgradeMethod;
  string Version;
  uint32 VoltageCaps;
};

[powerscript]

OLEObject ole_wsh
Any la_processor[]
string ls_message

 ole_wsh = CREATE OLEObject
 ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
 ole_wsh.Language = "vbscript"
 ole_wsh.AddCode('Function rtnProcessor()~r~n' &
 + 'DIM objProcessor(3)~r~n'  &
 + 'strComputer = "."~r~n'  &
 + 'Set objWMIService ='  &
 + '   GetObject("winmgmts:\\" & strComputer & "\root\cimv2")~r~n' &
 + 'Set colItems =' &
 +     objWMIService.ExecQuery("Select * from Win32_Processor")~r~n' &
 + 'For Each objItem in colItems~r~n' &
 + 'objProcessor(0) = objItem.ProcessorId~r~n' &
 + 'objProcessor(1) = objItem.MaxClockSpeed~r~n' &
 + 'objProcessor(2) = objItem.Name~r~n' &
 + 'objProcessor(3) = objItem.Description~r~n' &
 + 'Next~r~n' &
 + 'rtnProcessor = objProcessor~r~n' &
 + 'End Function')
 la_processor[] = ole_wsh.Eval("rtnProcessor")
 ole_wsh.DisconnectObject()
 DESTROY ole_wsh

ls_message = "Processor Id: " + string(la_processor[1]) + "~r~n" + &
+ "Maximum Clock Speed: " + string(la_processor[2]) + "~r~n" + &
+ "Name : " +string(la_processor[3]) + "~r~n" + &
+ "Description : " + string(la_processor[4])
MessageBox("Win32 Processor",ls_message)

To determine devices plugged into USB ports

[powerscript]

OLEObject ole_wsh
Any la_usb[]
string ls_message

 ole_wsh = CREATE OLEObject
 ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
 ole_wsh.Language = "vbscript"
 ole_wsh.AddCode('Function rtnUSB()~r~n' &
 + 'USBdevice = "" ~r~n'  &
 + 'strComputer = "."~r~n'  &
 + 'Set objWMIService = ' &
 + '  GetObject("winmgmts:\\" & strComputer & "\root\cimv2")~r~n' &
 + 'Set colItems = ' &
 + '  objWMIService.ExecQuery("Select * from Win32_USBHub")~r~n' &
 + 'For Each objItem in colItems~r~n' &
 + 'USBdevice = USBdevice & " , " & objItem.Description~r~n' &
 + 'Next~r~n' &
 + 'rtnUSB = USBdevice~r~n' &
 + 'End Function')

 ls_message = ole_wsh.Eval("rtnUSB")
 ole_wsh.DisconnectObject()
 DESTROY ole_wsh

ls_message = "Device(s): " + ls_message
MessageBox("USB",ls_message)

Obtain the inventory all the software installed on a computer (can take awhile!)

OLEObject ole_wsh
Any la_usb[]
string ls_message

 ole_wsh = CREATE OLEObject
 ole_wsh.ConnectToNewObject("MSScriptControl.ScriptControl")
 ole_wsh.Language = "vbscript"
 ole_wsh.AddCode('Function rtnSoftwares()~r~n' &
 + 'SoftwareList = "" ~r~n' + &
 + 'strComputer = "."~r~n' + &
 + 'Set objWMIService = ' + &
 + '   GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _~r~n' &
 + '& strComputer & "\root\cimv2")~r~n' &
 + 'Set colItems = ' &
 + '  objWMIService.ExecQuery("Select * from Win32_Product")~r~n' &
 + 'For Each objItem in colItems~r~n' &
 + 'SoftwareList = SoftwareList & " , " & objItem.Name  & + "(" & _~r~n' &
 + 'objItem.Version & ")"~r~n' &
 + 'Next~r~n' &
 + 'rtnSoftwares = SoftwareList~r~n' &
 + 'End Function')
 ls_message = ole_wsh.Eval("rtnSoftwares")
 ole_wsh.DisconnectObject()
 DESTROY ole_wsh

MessageBox("Software List",ls_message)

more examples at MSDN

Before using this technique, you may need to download and install the WMI ActiveX, here the URL.

See this related howto


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]