0

我正在创建自定义安装程序,并且在大多数情况下,我已经按照我想要的方式进行了设置,只是它缺少我想添加到设置中的两个功能。我已经进行了一些广泛的搜索,虽然我发现了很多类似的问题,但我无法对这些问题做出回应并根据我的特定需求对其进行修改并取得任何成功。

基本上我需要做的是为“检查:”创建一个自定义函数,用于检查当前安装的 DirectX 版本。我知道有“RegQueryStringValue”函数,并且我知道注册表中包含版本(HKLM\SOFTWARE\Microsoft\DirectX,版本)的密钥在哪里。我只是不知道如何实现代码来检查注册表中包含的版本,如果它报告的值小于 4.09.00.0904 以继续我在 [文件] 下输入的 DXSETUP。

我还想对“检查:”执行相同的例程,以便与 Visual C++ 2005 (x86) 一起使用。我相信这个会更简单,因为它只需要检查是否存在实际密钥(RegQueryKey?)而不是值。我相信 VC++ 2005 的关键是 HKLM\SOFTWARE\Microsoft\VisualStudio\8.0

如果有人可以帮助我,我将不胜感激,因为我已经为此搞砸了几个小时,试图将一些功能整合在一起,但没有取得多大成功。如果您需要我提供任何进一步的信息,我将非常乐意提供。

4

1 回答 1

3

CodePrepareToInstall.iss. InitializeSetup显示如何检查注册表项是否存在,您可以在DetectAndInstallPrerequisites. 我添加了一个CheckDXVersion函数,您可以Version从 DirectX 注册表项中传递字符串,检查 4.9 或更高版本(未经测试!)您也可以使用。

; -- CodePrepareToInstall.iss --
;
; This script shows how the PrepareToInstall event function can be used to
; install prerequisites and handle any reboots in between, while remembering
; user selections across reboots.

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "MyProg.exe"; DestDir: "{app}";
Source: "MyProg.chm"; DestDir: "{app}";
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme;

[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"

[Code]
const
  (*** Customize the following to your own name. ***)
  RunOnceName = 'My Program Setup restart';

  QuitMessageReboot = 'The installation of a prerequisite program was not completed. You will need to restart your computer to complete that installation.'#13#13'After restarting your computer, Setup will continue next time an administrator logs in.';
  QuitMessageError = 'Error. Cannot continue.';

var
  Restarted: Boolean;

function InitializeSetup(): Boolean;
begin
  Restarted := ExpandConstant('{param:restart|0}') = '1';

  if not Restarted then begin
    Result := not RegValueExists(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce', RunOnceName);
    if not Result then
      MsgBox(QuitMessageReboot, mbError, mb_Ok);
  end else
    Result := True;
end;

function CheckDXVersion(const VerString: String): Boolean;
var
  MajorVer, MinorVer: Integer;
  StartPos: Integer;
  TempStr: string;
begin
  (* Extract major version *)
  StartPos := Pos('.', VerString);
  MajorVer := StrToInt(Copy(VerString, 1, StartPos - 1);
  (* Remove major version and decimal point that follows *)
  TempStr := Copy(VerString, StartPos + 1, MaxInt);
  (* Find next decimal point *)
  StartPos := Pos('.', TempStr); 
  (* Extract minor version *)
  MinorVer := Copy(TempStr, 1, StartPos - 1);
  Result := (MajorVer > 4) or ((MajorVer = 4) and MinorVer >= 9));
end;

function DetectAndInstallPrerequisites: Boolean;
begin
  (*** Place your prerequisite detection and installation code below. ***)
  (*** Return False if missing prerequisites were detected but their installation failed, else return True. ***)

  //<your code here>

  Result := True;

  (*** Remove the following block! Used by this demo to simulate a prerequisite install requiring a reboot. ***)
  if not Restarted then
    RestartReplace(ParamStr(0), '');
end;

function Quote(const S: String): String;
begin
  Result := '"' + S + '"';
end;

function AddParam(const S, P, V: String): String;
begin
  if V <> '""' then
    Result := S + ' /' + P + '=' + V;
end;

function AddSimpleParam(const S, P: String): String;
begin
 Result := S + ' /' + P;
end;

procedure CreateRunOnceEntry;
var
  RunOnceData: String;
begin
  RunOnceData := Quote(ExpandConstant('{srcexe}')) + ' /restart=1';
  RunOnceData := AddParam(RunOnceData, 'LANG', ExpandConstant('{language}'));
  RunOnceData := AddParam(RunOnceData, 'DIR', Quote(WizardDirValue));
  RunOnceData := AddParam(RunOnceData, 'GROUP', Quote(WizardGroupValue));
  if WizardNoIcons then
    RunOnceData := AddSimpleParam(RunOnceData, 'NOICONS');
  RunOnceData := AddParam(RunOnceData, 'TYPE', Quote(WizardSetupType(False)));
  RunOnceData := AddParam(RunOnceData, 'COMPONENTS', Quote(WizardSelectedComponents(False)));
  RunOnceData := AddParam(RunOnceData, 'TASKS', Quote(WizardSelectedTasks(False)));

  (*** Place any custom user selection you want to remember below. ***)

  //<your code here>

  RegWriteStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\RunOnce', RunOnceName, RunOnceData);
end;

function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  ChecksumBefore, ChecksumAfter: String;
begin
  ChecksumBefore := MakePendingFileRenameOperationsChecksum;
  if DetectAndInstallPrerequisites then begin
    ChecksumAfter := MakePendingFileRenameOperationsChecksum;
    if ChecksumBefore <> ChecksumAfter then begin
      CreateRunOnceEntry;
      NeedsRestart := True;
      Result := QuitMessageReboot;
    end;
  end else
    Result := QuitMessageError;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := Restarted;
end;
于 2012-11-09T23:08:01.280 回答