gpt4 book ai didi

inno-setup - 有没有办法在 Inno Setup 中读取系统信息

转载 作者:行者123 更新时间:2023-12-04 14:55:55 57 4
gpt4 key购买 nike

在安装过程中(仅在欢迎向导页面),有没有办法在 Inno Setup 中读取系统信息?

我的意思是:

  • 内存
  • 操作系统
  • CPU
  • 用户
  • 知识产权
  • MAC地址。

  • 知道这将是一件好事。我想把这些信息放在一个文本文件中,我会保存在我的电脑上。我似乎根本无法在网上找到有关此的 Material ,希望有人有这方面的经验,可以提供帮助吗?

    最佳答案

    有许多不同的方法可以检索所有这些信息。
    但检索所有这些的一种通用方法是 WMI query .
    您会感兴趣的 WMI 类是:

  • 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: Variant;
    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;
    对于 better Variant support,代码需要 Inno Setup 的 Unicode 版本(Inno Setup 6 的唯一版本)。 .
    SWbemObjectSet.ItemIndex methodWin32_NetworkAdapterConfiguration 一起使用在较旧的 Windows XP 上不可用。见 Iterate SWbemObjectSet in Windows XP and Inno Setup .

    它将为您提供以下信息:
    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

    要查看相关类中的所有可用信息,请在命令行上运行:
    wmic computersystem get * /format:value
    wmic os get * /format:value
    wmic cpu get * /format:value
    wmic nicconfig get * /format:value

    关于inno-setup - 有没有办法在 Inno Setup 中读取系统信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40762683/

    57 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com