Страница 1 из 1

Delphi & WMI

Добавлено: 20 апр 2007, 12:35
Sergey_
Работает, как надо, все выводит, но в конце вылетам с AV. Может кто сталкивался?

Код: Выделить всё

  CoInitialize(nil);
  Locator := TSWbemLocator.Create(nil);
  Services := Locator.ConnectServer(const_ComputerName, const_Namespace,'','','','', 0, nil);
  ObjSet := Services.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=TRUE', const_SQLLang, 0, nil);
  if ObjSet.Count > 0 then
  begin
    enum := ObjSet._NewEnum as IEnumVariant;
    while enum.Next( 1, Res, cardFetched) = S_OK do
    begin
      curObj := IInterface(Res) as ISWbemObject;
      WriteLn( curObj.GetObjectText_(0) );
      curObj := nil;
    end;
  end;
[B]  Locator.Free;[/B]  
  CoUninitialize;

Re: Delphi & WMI

Добавлено: 20 апр 2007, 17:08
Лелик_1044
ты бы полнстью привел с перемеными и прочим

Re: Delphi & WMI

Добавлено: 22 апр 2007, 12:40
Sergey_
консольное приложение...

Код: Выделить всё

program proc;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Variants,
  ActiveX,
  WbemScripting_TLB in '..\..\Delphi7\Imports\WbemScripting_TLB.pas';

const
  const_ComputerName = '.';
  const_Namespace = 'root/CIMV2';
  const_SQLLang = 'WQL';

var
  Locator  :  TSWbemLocator;
  Services :  ISWbemServices;
  ObjSet   :  ISWbemObjectSet;
  enum     :  IEnumVariant;
  curObj   :  ISWbemObject;

  Res      : OleVariant;
  cardFetched : Cardinal;
  curConfig : ISWbemObject;
begin

  CoInitialize(nil);
  Locator := TSWbemLocator.Create(nil);
  Services := Locator.ConnectServer(const_ComputerName, const_Namespace,'','','','', 0, nil);
  ObjSet := Services.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled=TRUE', const_SQLLang, 0, nil);
  if ObjSet.Count > 0 then
  begin
    enum := ObjSet._NewEnum as IEnumVariant;
    while enum.Next( 1, Res, cardFetched) = S_OK do
    begin
      curObj := IInterface(Res) as ISWbemObject;
      WriteLn( curObj.GetObjectText_(0) );
      curObj := nil;
    end;
  end;
  Locator.Free;
  CoUninitialize;

end.