根据条件写入注册表

Raj*_*pal 3 inno-setup

我想根据操作系统写入注册表。我有操作系统检测功能,发现你可以在注册表部分放置一个检查功能,所以尝试了以下操作:

Root: HKLM; SubKey: Software\Microsoft\Windows; ValueType: dword; ValueName: Test; ValueData: 1; Flags: createvalueifdoesntexist; Check: IsWindows7
Run Code Online (Sandbox Code Playgroud)

但它不起作用,这意味着当我在 Win7 和 WinXP 上安装时,它在两种情况下都将值写入注册表。

这是检测操作系统的代码:

function IsWindows7(): Boolean;
var
  Version: TWindowsVersion;
begin
  GetWindowsVersionEx(Version);

  // Windows 7 version is 6.1 (workstation)
  if (Version.Major = 6)  and
     (Version.Minor = 1) and
     (Version.ProductType = VER_NT_WORKSTATION)
  then
    Result := True
  else
    Result := False;
end;
Run Code Online (Sandbox Code Playgroud)

任何想法/建议?

Ant*_*rko 5

请参阅下面我为您提供的解决方案:

[Registry]

Root: HKLM; SubKey: {code:IsWindows7}; ValueType: dword; ValueName: Test; ValueData: 1; Flags: createvalueifdoesntexist; Check: IsWindows7

[Code]

function IsWindows7(S: String) : string;
var
  Version: TWindowsVersion;
begin

 GetWindowsVersionEx(Version);

  // Windows 7 version is 6.1 (workstation)
  if (Version.Major = 6)  and
     (Version.Minor = 1) and
     (Version.ProductType = VER_NT_WORKSTATION)
  then
    Result := '<registry path for win 7>'
else
    Result := '<registry path for other win os >';

end;
Run Code Online (Sandbox Code Playgroud)

快乐编码!