Конференция "KOL" » WMI and ActiveKOL
 
  • Dodfr (16.02.08 04:32) [0]
    Hi,

    I am trying to do WMI calls to retrieve CPU Temperature (ACPI may do it too but I don't know how to do it).

    So I used ActiveKOL and imported WbemScripting_TLB using TLB2KOL converter that created WbemScripting_TLBKOL I added into my uses clause and also Variants and ActiveX.

    But it crashes at "Locator := CoSWbemLocator.Create;", ActiveKOL readme's say I have to do declare a variable and do a New(xxx CreatePerented(Form)) derived from TOleCtl, but I don't know how ?

    Here is the code, thanx.

    function GetWMIstring2 (wmiHost, wmiClass, wmiProperty : string):string;
    var  // These are all needed for the WMI querying process
     Locator:  ISWbemLocator;
     Services: ISWbemServices;
     SObject:  ISWbemObject;
     ObjSet:   ISWbemObjectSet;
     SProp:    ISWbemProperty;
     Enum:     IEnumVariant;
     Value:    Cardinal;
     TempObj:  OleVariant;
     SN: string;
    begin
     Locator := CoSWbemLocator.Create;
      Services :=  Locator.ConnectServer(wmiHost, 'root\wmi', '', '', '','', 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.PopupMenu1MenuAboutMenu(Sender: PMenu; Item: Integer);
    begin
    MessageOK(getWMIstring2('','MSAcpi_ThermalZoneTemperature','CurrentTemperature') );
    end;
  • Jon © (16.02.08 15:26) [1]
    You forgort OleInit

    program Forms;

    uses
     KOL, WbemScripting_TLBKOL, ActiveX, Variants;

    function GetWMIstring2 (wmiHost, wmiClass, wmiProperty : string):string;
    var  // These are all needed for the WMI querying process
    Locator:  ISWbemLocator;
    Services: ISWbemServices;
    SObject:  ISWbemObject;
    ObjSet:   ISWbemObjectSet;
    SProp:    ISWbemProperty;
    Enum:     IEnumVariant;
    Value:    Cardinal;
    TempObj:  OleVariant;
    SN: string;
    begin
    Locator := CoSWbemLocator.Create;
     Services :=  Locator.ConnectServer(wmiHost, 'root\wmi', '', '', '','', 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 ButtonClick(Dummy: Pointer; Sender: PControl);
    begin
     MsgOK(getWMIstring2('','MSAcpi_ThermalZoneTemperature','CurrentTemperature') );
    end;

    begin
     Applet := NewForm(nil,'Test').SetSize(200,200);
     with NewButton(Applet,'Temp')^ do
     begin
       CenterOnParent;
       OnClick := TOnEvent(MakeMethod(nil,@ButtonClick));
     end;
     OleInit;
     Run(Applet);
     OleUnInit;
    end.



    The above code works perfectly!
  • Dodfr (16.02.08 16:15) [2]
    I'll test it, thank you !
 
Конференция "KOL" » WMI and ActiveKOL
Есть новые Нет новых   [134431   +14][b:0][p:0.001]