1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ActiveX, WbemScripting_TLB;
type TForm1 = class(TForm) Memo1: TMemo; Label1: TLabel; procedure FormActivate(Sender: TObject); private public end;
var Form1: TForm1; aLoc: ISWbemLocator; aSrv: ISWbemServices; aObjSet: ISWbemObjectSet; pEnum: IEnumVARIANT; vOut: OleVariant; dwRetrieved: LongWord; hRes: HResult; cWQL, sWQL: string; st: TStringList;
implementation
{$R *.dfm}
function GetWMIstring (wmiHost, wmiClass, wmiProperty : string):string; var Locator: ISWbemLocator; Services: ISWbemServices; SObject: ISWbemObject; ObjSet: ISWbemObjectSet; SProp: ISWbemProperty; Enum: IEnumVariant; Value: Cardinal; TempObj: OleVariant; SN: string; begin try Locator := CoSWbemLocator.Create; Services := Locator.ConnectServer(wmiHost, 'root\cimv2', '', '', '','', 0, nil); ObjSet := Services.ExecQuery('SELECT * FROM '+wmiClass, 'WQL', wbemFlagReturnImmediately and wbemFlagForwardOnly , nil); Enum := (ObjSet._NewEnum) as IEnumVariant; while (Enum.Next(1, TempObj, Value) = S_OK) do begin SObject := IUnknown(tempObj) as ISWBemObject; SProp := SObject.Properties_.Item(wmiProperty, 0); if VarIsNull(SProp.Get_Value) then result := '' else begin SN := SProp.Get_Value; result := SN; end; end; except on exception do result := ''; end; end;
procedure TForm1.FormActivate(Sender: TObject); var tmpstr : string; begin tmpstr := getWMIstring('','Win32_VideoController ','AdapterRAM'); if tmpstr <> '' then Label1.caption:= tmpstr +' Bytes VideoRAM'; end;
end. |