Is there a way to read the system's information in Inno Setup, during installation (just at the welcome wizard page)?
By this I mean:
- RAM
- OS
- CPU
- user
- IP
- MAC adress.
It would be a good thing to know. I would like to put this information in say a text document that I would save on my computer. I cannot seem to find material on this online at all, and was hoping if anyone had experience with this, could help?
There are many different ways to retrieve all these information.
But one universal way to retrieve all of them is a WMI query.
WMI classes that will interest you are:
Win32_ComputerSystem
Win32_OperatingSystem
Win32_Processor
Win32_NetworkAdapterConfiguration
function WbemQuery(WbemServices: Variant; Query: string): Variant;
var
WbemObjectSet: Variant;
begin
Result := Null;
WbemObjectSet := WbemServices.ExecQuery(Query);
if not VarIsNull(WbemObjectSet) and (WbemObjectSet.Count > 0) then
begin
Result := WbemObjectSet.ItemIndex(0);
end;
end;
procedure CollectInformation;
var
Query: string;
WbemLocator, WbemServices: Variant;
ComputerSystem, OperatingSystem, Processor, NetworkAdapters, NetworkAdapter: Variant;
IPAddresses: array of string;
I, I2: Integer;
begin
WbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
WbemServices := WbemLocator.ConnectServer('.', 'root\CIMV2');
Query := 'SELECT TotalPhysicalMemory, UserName FROM Win32_ComputerSystem';
ComputerSystem := WbemQuery(WbemServices, Query);
if not VarIsNull(ComputerSystem) then
begin
Log(Format('TotalPhysicalMemory=%s', [ComputerSystem.TotalPhysicalMemory]));
Log(Format('UserName=%s', [ComputerSystem.UserName]));
end;
Query := 'SELECT Caption FROM Win32_OperatingSystem';
OperatingSystem := WbemQuery(WbemServices, Query);
if not VarIsNull(OperatingSystem) then
begin
Log(Format('OperatingSystem=%s', [OperatingSystem.Caption]));
end;
Query := 'SELECT Name FROM Win32_Processor';
Processor := WbemQuery(WbemServices, Query);
if not VarIsNull(Processor) then
begin
Log(Format('Processor=%s', [Processor.Name]));
end;
Query :=
'SELECT IPEnabled, IPAddress, MACAddress FROM Win32_NetworkAdapterConfiguration';
NetworkAdapters := WbemServices.ExecQuery(Query);
if not VarIsNull(NetworkAdapters) then
begin
for I := 0 to NetworkAdapters.Count - 1 do
begin
NetworkAdapter := NetworkAdapters.ItemIndex(I);
if (not VarIsNull(NetworkAdapter.MACAddress)) and NetworkAdapter.IPEnabled then
begin
Log(Format('Adapter %d MAC=%s', [I, NetworkAdapter.MACAddress]));
if not VarIsNull(NetworkAdapter.IPAddress) then
begin
IPAddresses := NetworkAdapter.IPAddress;
for I2 := 0 to GetArrayLength(IPAddresses) - 1 do
begin
Log(Format('Adapter %d IP %d=%s', [I, I2, IPAddresses[I2]]));
end;
end;
end;
end;
end;
end;
The code requires Unicode version of Inno Setup for a better Variant
support.
The SWbemObjectSet.ItemIndex
method used with Win32_NetworkAdapterConfiguration
is not available on Windows XP an older. See Iterate SWbemObjectSet in Windows XP and Inno Setup.
It will get you information like:
TotalPhysicalMemory=12835962880
UserName=domain\martin
OperatingSystem=Microsoft Windows 10 Home
Processor=Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
Adapter 1 MAC=11:51:67:D0:10:21
Adapter 1 IP 0=192.168.78.2
Adapter 1 IP 1=ef08::8da9:601e:3f8a:da00
Adapter 2 MAC=80:06:E6:10:F7:B9
Adapter 2 IP 0=192.168.1.3
To see all available information in involved classes, run this on command-line:
wmic computersystem get * /format:value
wmic os get * /format:value
wmic cpu get * /format:value
wmic nicconfig get * /format:value