Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "KOL";
Текущий архив: 2009.06.21;
Скачать: [xml.tar.bz2];

Вниз

WMI and ActiveKOL   Найти похожие ветки 

 
Dodfr   (2008-02-16 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 ©   (2008-02-16 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   (2008-02-16 16:15) [2]

I"ll test it, thank you !



Страницы: 1 вся ветка

Форум: "KOL";
Текущий архив: 2009.06.21;
Скачать: [xml.tar.bz2];

Наверх




Память: 0.45 MB
Время: 0.005 c
2-1240982587
AIK
2009-04-29 09:23
2009.06.21
Required package VCL30 not found


15-1239967211
passlight
2009-04-17 15:20
2009.06.21
Кому-нибудь нужны книги по программированию (базы данных, .NET)?


15-1239378087
Rouse_
2009-04-10 19:41
2009.06.21
И мне чтоль какую нибудь голосовалку сделать? :)


2-1241207260
бульдозер
2009-05-01 23:47
2009.06.21
CreateProcess определить готовность запускаемого приложения


11-1203125531
Dodfr
2008-02-16 04:32
2009.06.21
WMI and ActiveKOL





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский