Delphi & WMI

Ответить

Код подтверждения
Введите код в точности так, как вы его видите. Регистр символов не имеет значения.

BBCode ВКЛЮЧЁН
[img] ВКЛЮЧЁН
[url] ВКЛЮЧЁН
Смайлики ОТКЛЮЧЕНЫ

Обзор темы
   

Развернуть Обзор темы: Delphi & WMI

Re: Delphi & WMI

Sergey_ » 22 апр 2007, 12:40

консольное приложение...

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

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.

Re: Delphi & WMI

Лелик_1044 » 20 апр 2007, 17:08

ты бы полнстью привел с перемеными и прочим

Delphi & WMI

Sergey_ » 20 апр 2007, 12:35

Работает, как надо, все выводит, но в конце вылетам с 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;

Вернуться к началу