Einzelnen Beitrag anzeigen

nanix
(Gast)

n/a Beiträge
 
#8

Re: WMI (Windows Management Instrumentation) + Demo

  Alt 11. Jan 2010, 19:43
There is a bug SetLength(_WMIResults.Instance, WMIObjectSet.Count); line 595

when i use it with my code

Delphi-Quellcode:
unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,WMI_Scripting, StdCtrls, ComCtrls;

 const
   Days : array[0..37] of string =
   (
     'Processor',
     'BIOS',
     'SystemSlot',
     'Bus',
     'SystemEnclosure',
     // Motherboard
     'BaseBoard',
     'MotherboardDevice',

     'DMAChannel',
     // Controler
     '1394Controller',
     'IDEController',
     'FloppyController',
     'PCMCIAController',
     'USBController',



     // Drives
     'CDROMDrive',
     'DiskDrive',
     'TapeDrive',

     // Network
     'NetworkAdapter',
     'NetworkAdapterConfiguration',

      // Printer
     'Printer',
     'PrinterConfiguration',


      // Device
      'OnBoardDevice',
      'InfraredDevice',
      'PointingDevice',
      'SoundDevice',
{IRQResource
Keyboard


    PrintJob



ParallelPort


PnPEntity

PortableBattery
PortConnector
PortResource
POTSModem
PowerManagementEvent


Refrigeration
SerialPort
SerialPortConfiguration


SystemEnclosure

SystemSlot    }







     // Memory
     'MemoryArray',
     'MemoryDevice',
     'PhysicalMemory',
     'PhysicalMemory',
     'SMBIOSMemory',
     'PhysicalMemoryArray',
     'SystemMemoryResource',
     'CacheMemory',

     // Graphics
     'DesktopMonitor',
     'DisplayControllerConfiguration',
     'DisplayConfiguration',
     'VideoController',
     'VideoConfiguration',
     'VideoSettings'
     ) ;

type
  TForm6 = class(TForm)
    TreeView1: TTreeView;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  type
  propertys=record
    index:integer;
    name:string;
    Value:String;
  end;

  type
  instance=record
    Index:Integer;
    name:string;
    Propertys: array of Propertys;

  end;

 type
 WMIClass= record
  index:integer;
  name:string;
  Instances:array of instance;
 end;



var
  Form6: TForm6;
  wmi_class:array of WMIClass;
implementation

{$R *.dfm}
 function GetNodeByText
(ATree : TTreeView; AValue:String;
 AVisible: Boolean): TTreeNode;
var
    Node: TTreeNode;
begin
  Result := nil;
  if ATree.Items.Count = 0 then Exit;
  Node := ATree.Items[0];
  while Node <> nil do
  begin
    if UpperCase(Node.Text) = UpperCase(AValue) then
    begin
      Result := Node;
      if AVisible then
        Result.MakeVisible;
      Break;
    end;
    Node := Node.GetNext;
  end;
end;



end;

end;

procedure TForm6.FormCreate(Sender: TObject);
var
i,j:integer;
WMIResults: TWMIInfo;

_Days: Integer;
_Instance:Integer;
_Propertys:Integer;

propertycount:integer;
dayscount:integer;
instancecount:integer;

begin




SetLength(Wmi_class,Length(Days));
for _Days:=0 to Length(Days)-1 do begin

if not WMIGetInfo('.','', '','', 'Win32_'+Days[_Days], WMIResults) then begin
showmessage('error');
Continue;
end;


If WMIResults.Instance = nil Then begin
 wmi_class[_Days].name:=Days[_Days]+' Not Supported';
Continue;
end;


for _Instance := 0 to Length(WMIResults.Instance)-1 do

for _Propertys := 0 to Length(WMIResults.PropName)-1 do begin

dayscount:=Length(Days);
instancecount:=Length(WMIResults.Instance);
propertycount:=Length(WMIResults.PropName);

SetLength(wmi_class[_Days].Instances,instancecount);
SetLength(wmi_class[_Days].Instances[_Instance].Propertys,propertycount);



          wmi_class[_Days].name:=Days[_Days];
          wmi_class[_Days].Instances[_Instance].Name:='Instance '+inttostr(_Instance);
          wmi_class[_Days].Instances[_Instance].Index:=_Instance;
          wmi_class[_Days].Instances[_Instance].Propertys[_Propertys].index:=_Propertys;
          wmi_class[_Days].Instances[_Instance].Propertys[_Propertys].name:=WMIResults.PropName[_Propertys];
          wmi_class[_Days].Instances[_Instance].Propertys[_Propertys].Value:=WMIRead(WMIResults, _Instance, _Propertys);


end;




end;




end;

end.
  Mit Zitat antworten Zitat