Recent

Author Topic: hardware and software inventory  (Read 3728 times)

anv

  • Newbie
  • Posts: 1
hardware and software inventory
« on: March 10, 2017, 01:47:05 pm »
I am trying to create an application that grabs information about the installed hardware and software of the PCs at my work. The idea is to run on every PC an application that grabs the relevant info and automatically uploads it to a database. The main target is to detect the use of unliscensed software.

Searching info in the forum I managed to create a 32 bits program that reads the data from the windows registry in 32 and 64 bits windows ad builds a table of installed apps. I think I will do a simple search on the disk to find something else.

My questions are:
1) a way to get an unique identifier of the PC. May be the ethernet mac address, the windows serial number or something like this.
2) a way to get the system name and/or the ip address

I can obtain some of this data RunCommand('ipconfig.exe',['/all'],s); but I prefer a cleaner way that does not open a windows for this.

3) a wey to get information about processor, ram and disk (total and free)

4) a way to run the program silently once a day (without opening a window if possible).

I think this program may be userfull for other people and if you want it ask me and I will upload it to github.

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: hardware and software inventory
« Reply #1 on: March 12, 2017, 07:23:35 pm »
Use WMI.
Often administrators use scripts for example in powershell. But if you want the FPC, this may help:
Code: Pascal  [Select][+][-]
  1. {$APPTYPE CONSOLE}
  2. program Project1;
  3.  
  4. uses Windows, SysUtils, Variants, ComObj, ActiveX;
  5.  
  6. function GetDynaNameProperty(const Source: Variant;
  7.   const PropertyName: AnsiString): Variant;
  8. var
  9.   Desc: TCallDesc;
  10. begin
  11.   ZeroMemory(@Desc, SizeOf(Desc));
  12.   Desc.CallType := DISPATCH_PROPERTYGET;
  13.   Move(PropertyName[1], Desc.ArgTypes[0], Length(PropertyName));
  14.   VarDispProc(@Result, Source, @Desc, nil);
  15. end;
  16.  
  17. procedure WriteWMIQuery(const FWMIService: OleVariant;
  18.   const Query: WideString; const PropNames: array of string);
  19. const
  20.   WBEM_FLAG_FORWARD_ONLY = $20;
  21.   WBEM_RETURN_IMMEDIATELY = $10;
  22. var
  23.   FWbemCollection: OleVariant;
  24.   Enum: IEnumvariant;
  25.   iValue: ULONG;
  26.   FWbemObject: OleVariant;
  27.   i, k: Integer;
  28.   Prop: Variant;
  29. begin
  30.   Writeln('[', Query, ']');
  31.   FWbemCollection := FWMIService.ExecQuery(Query, 'WQL',
  32.     WBEM_FLAG_FORWARD_ONLY or WBEM_RETURN_IMMEDIATELY);
  33.   Enum := IUnknown(FWbemCollection._NewEnum) as IEnumVariant;
  34.   while Enum.Next(1, FWbemObject, iValue) = 0 do
  35.   begin
  36.     for i := Low(PropNames) to High(PropNames) do
  37.     begin
  38.       Prop := GetDynaNameProperty(FWbemObject, PropNames[i]);
  39.       if VarIsArray(Prop) then
  40.         for k := VarArrayLowBound(Prop, 1) to VarArrayHighBound(Prop, 1) do
  41.           Writeln(PropNames[i], '[', k, ']: ', Prop[k])
  42.       else
  43.         Writeln(PropNames[i], ': ', Prop);
  44.     end;
  45.     Writeln('');
  46.     FWbemObject:=Unassigned;
  47.   end;
  48. end;
  49.  
  50. const
  51.   WbemUser = '';
  52.   WbemPassword = '';
  53.   WbemComputer = 'localhost';
  54. var
  55.   SWbemLocator: OleVariant;
  56.   WMIService: OleVariant;
  57. begin
  58.   NullStrictConvert := False;
  59.   SWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
  60.   WMIService := SWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
  61.   WriteWMIQuery(WMIService, 'select * from Win32_ComputerSystemProduct',
  62.     ['Vendor', 'Version']);
  63.   WriteWMIQuery(WMIService, 'select * from Win32_ComputerSystem',
  64.     ['Name', 'Manufacturer', 'PrimaryOwnerName', 'SystemType']);
  65.   WriteWMIQuery(WMIService, 'select * from Win32_OperatingSystem',
  66.     ['Caption', 'Version', 'OSArchitecture', 'SerialNumber', 'BootDevice', 'TotalVisibleMemorySize']);
  67.   WriteWMIQuery(WMIService, 'select * from Win32_NetworkAdapterConfiguration where IPEnabled=True',
  68.     ['Caption', 'MACAddress', 'IPAddress']);
  69.   Readln;
  70. end.

 

TinyPortal © 2005-2018