是一种在Inno Setup中读取系统信息的方法 [英] Is there a way to read the system's information in Inno Setup

查看:288
本文介绍了是一种在Inno Setup中读取系统信息的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在安装过程中(仅在欢迎向导页面上)在Inno Setup中读取系统信息?

Is there a way to read the system's information in Inno Setup, during installation (just at the welcome wizard page)?

我的意思是:

  • RAM
  • 操作系统
  • CPU
  • 用户
  • IP
  • MAC地址.

知道这将是一件好事.我想将此信息放在我要保存在计算机上的文本文档中.我似乎根本无法在此网上找到任何资料,并希望是否有人对此有所帮助?

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.

但检索所有这些文件的一种通用方法是 WMI查询.

But one universal way to retrieve all of them is a WMI query.

您会感兴趣的WMI类:

WMI classes that will interest you are:

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;

代码要求更好的Variant,需要Inno Setup的Unicode版本(Inno Setup 6唯一的版本).支持.

The code requires Unicode version of Inno Setup (the only version as of Inno Setup 6) for a better Variant support.

SWbemObjectSet.ItemIndex方法Win32_NetworkAdapterConfiguration一起使用的>在Windows XP或更早的版本上不可用.请参见在Windows XP和Inno Setup中迭代SWbemObjectSet .

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

这篇关于是一种在Inno Setup中读取系统信息的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆