RRUZ / delphi-wmi-class-generator

Creates Object Pascal classes to access the WMI

Home Page:https://theroadtodelphi.wordpress.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibility to share the WMI connection between the objects generated by the tool [Feature Request]

GoogleCodeExporter opened this issue · comments

What steps will reproduce the problem?
- Create the units with WMI Class Generator (eg. uWin32_OperatingSystem, 
uWin32_LocalTime)
- Trying to retrieve from remote PC the WMIdata using:

  objWMIOperatingSystem := TWin32_OperatingSystem.Create(false);
  objWMILocalTime := TWin32_LocalTime.Create(false);

  objWMIOperatingSystem.WmiServer := sWMIremotePC;
  objWMIOperatingSystem.WmiUser := sWMIuser;
  objWMIOperatingSystem.WmiPass := sWMIpass;
  objWMIOperatingSystem.LoadWmiData;

  objWMILocalTime.WmiServer := sWMIRemotePC;
  objWMILocalTime.WmiUser := sWMIuser;
  objWMILocalTime.WmiPass := sWMIpass;
  objWMILocalTime.LoadWmiData;


What is the expected output? What do you see instead?
- When I call .LoadWmiData it takes long to retrieve the information at both 
calls, because the WMI connection are not shared between the objects. Sharing 
the WMI connection, the second information should retrieve much faster because 
I would be already authenticated at remote PC. 

What version of the product are you using? On what operating system?
Delphi XE, Windows 7 (x86)


Original issue reported on code.google.com by an...@andrefm.com on 19 Mar 2011 at 3:03

Original comment by Rodrigo.Ruz.V@gmail.com on 2 Apr 2011 at 8:10

  • Changed state: Accepted
Your suggestion was included in the new version 


check this sample application 

{$APPTYPE CONSOLE}
{
 This sample application how share a remote wmi connection to improve the performance,
 the only requisite to share a wmi is which the classes ti access must be in the same namespace
}
uses
  SysUtils,
  //WbemScripting_TLB in '..\..\WbemScripting_TLB.pas',
  uWmiDelphiClass in '..\..\uWmiDelphiClass.pas',
  uWin32_BIOS in '..\..\root_CIMV2\uWin32_BIOS.pas',
  uWin32_OperatingSystem in '..\..\root_CIMV2\uWin32_OperatingSystem.pas';

var
  RemoteWmiConn  : TWmiConnection;
  RemoteBiosInfo : TWin32_BIOS;
  RemoteOSInfo   : TWin32_OperatingSystem;
  i              : integer;
  dt             : TDateTime;
begin
   ReportMemoryLeaksOnShutdown:=(DebugHook<>0);
   try
     RemoteWmiConn:=TWmiConnection.Create;
     try
       RemoteWmiConn.WmiServer:='192.168.52.128';
       RemoteWmiConn.WmiUser  :='Administrator';
       RemoteWmiConn.WmiPass  :='desarrollo';
       RemoteWmiConn.WmiNameSpace:='root\cimv2';
       Write('Connecting...');
       dt:=Now;
       RemoteWmiConn.WmiConnect(True);

       if RemoteWmiConn.WmiConnected then
       begin
         WriteLn(FormatDateTime('hh:nn:ss.zzz',Now-dt));


         RemoteBiosInfo:=TWin32_BIOS.Create(False); //must be false to share the connection
         try
           RemoteBiosInfo.WmiConnection:=RemoteWmiConn;    //assign the shared connection
           RemoteBiosInfo.LoadWmiData;
           Writeln('Bios Info');
           Writeln('---------');
           Writeln('Serial Number       '+RemoteBiosInfo.SerialNumber);
           Writeln('BuildNumber         '+RemoteBiosInfo.BuildNumber);
           if RemoteBiosInfo.BIOSVersion.Count>0 then
           Writeln('Version             '+RemoteBiosInfo.BIOSVersion[0]);
           Writeln('Identification Code '+RemoteBiosInfo.IdentificationCode);
           Writeln('Manufacturer        '+RemoteBiosInfo.Manufacturer);
           Writeln('SoftwareElementID   '+RemoteBiosInfo.SoftwareElementID);
           Writeln('Release Date        '+DateToStr(RemoteBiosInfo.ReleaseDate));
           Writeln('Install Date        '+DateToStr(RemoteBiosInfo.InstallDate));
           Writeln('Target S.O          '+GetTargetOperatingSystemAsString(RemoteBiosInfo.TargetOperatingSystem));
           Writeln('Soft. element state '+GetSoftwareElementStateAsString(RemoteBiosInfo.SoftwareElementState));

           Writeln('');
           Writeln('Bios Characteristics');
           Writeln('--------------------');

           for i:=Low(RemoteBiosInfo.BiosCharacteristics)  to High(RemoteBiosInfo.BiosCharacteristics) do
            Writeln(GetBiosCharacteristicsAsString(RemoteBiosInfo.BiosCharacteristics[i]));

         finally
           RemoteBiosInfo.Free;
         end;

         RemoteOSInfo:=TWin32_OperatingSystem.Create(False); //must be false to share the connection
         try
           Writeln('');
           Writeln('');
           Writeln('OS Info');
           Writeln('-------');
           RemoteOSInfo.WmiConnection:=RemoteWmiConn;    //assign the shared connection
           RemoteOSInfo.LoadWmiData;
           Writeln('Caption         '+RemoteOSInfo.Caption);
           Writeln('Description     '+RemoteOSInfo.Description);
           Writeln('OS Architecture '+RemoteOSInfo.OSArchitecture);
           Writeln('Registered User '+RemoteOSInfo.RegisteredUser);
           Writeln('Country Code    '+RemoteOSInfo.CountryCode);
           Writeln('Number Of Users '+IntToStr(RemoteOSInfo.NumberOfUsers));
           Writeln('Install Date    '+DateToStr(RemoteOSInfo.InstallDate));
         finally
           RemoteOSInfo.Free;
         end;


       end
       else
       Writeln('No connected');
     finally
      RemoteWmiConn.Free;
     end;
   except
    on E:Exception do
     Writeln(E.Classname, ': ', E.Message);
   end;

 Readln;
end.

Original comment by Rodrigo.Ruz.V@gmail.com on 2 Apr 2011 at 8:12

  • Changed state: Done