在Inno Setup中传递条件参数

时间:2013-01-18 05:28:26

标签: inno-setup

我是Inno Setup的新手,我已经阅读了文档。现在我知道Inno Setup可以接受不同的/自定义参数,并且可以通过Pascal脚本进行处理。但问题是,我不知道如何用Pascal写。

我希望我可以获得有关编码的帮助。

我想将/ NOSTART参数传递给我的设置文件,该文件告诉设置禁用(取消选中)“启动”上的复选标记,如果未提供/ NOSTART,它将启用(检查)检查标记“启动”

enter image description here

或者如果可能的话,不需要启动页面,并通过代码执行所有操作。

3 个答案:

答案 0 :(得分:6)

由于您无法强制修改节条目的标志并直接访问RunList将是一个非常脏的解决方法,我正在使用这两个postinstall条目,而一个没有{{指定3}}标志,第二个标志。因此,第一个条目表示选中的启动复选框,第二个条目表示未选中的启动复选框。使用哪一个是由unchecked参数函数控制的,其中检查命令行尾部是否包含/NOSTART参数。

另外,我使用了一个更直接的函数来确定命令行尾中是否包含某个参数。它使用Check函数以不区分大小写的方式比较文本。如果要以区分大小写的方式比较参数文本,可以将其替换为CompareText函数。这是脚本:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Run]
Filename: "calc.exe"; Description: "Launch calculator"; \
    Flags: postinstall nowait skipifsilent; Check: LaunchChecked
Filename: "calc.exe"; Description: "Launch calculator"; \
    Flags: postinstall nowait skipifsilent unchecked; Check: not LaunchChecked
[Code]
function CmdLineParamExists(const Value: string): Boolean;
var
  I: Integer;  
begin
  Result := False;
  for I := 1 to ParamCount do
    if CompareText(ParamStr(I), Value) = 0 then
    begin
      Result := True;
      Exit;
    end;
end;

function LaunchChecked: Boolean;
begin
  Result := not CmdLineParamExists('/NOSTART');
end;

答案 1 :(得分:3)

所以有点研究阅读和阅读..我得到了答案。

这是我的代码(“GetCommandLineParam”除外)

[Code]
{
var
  StartNow: Boolean;
}

function GetCommandLineParam(inParam: String): String;
var
  LoopVar : Integer;
  BreakLoop : Boolean;
begin
  { Init the variable to known values }
  LoopVar :=0;
  Result := '';
  BreakLoop := False;

  { Loop through the passed in arry to find the parameter }
  while ( (LoopVar < ParamCount) and
          (not BreakLoop) ) do
  begin
    { Determine if the looked for parameter is the next value }
    if ( (ParamStr(LoopVar) = inParam) and
         ( (LoopVar+1) <= ParamCount )) then
    begin
      { Set the return result equal to the next command line parameter }
      Result := ParamStr(LoopVar+1);

      { Break the loop }
      BreakLoop := True;
    end;

    { Increment the loop variable }
    LoopVar := LoopVar + 1;
  end;
end;

{
function InitializeSetup(): Boolean;
var
  NOSTART_Value : String;

begin
  NOSTART_Value := GetCommandLineParam('/NOSTART');

  if(NOSTART_Value = 'false') then
    begin
      StartNow := True
    end
  else
    begin
      StartNow := False
    end;

  Result := True;
end;
}

procedure CurStepChanged(CurStep: TSetupStep);
var
  Filename: String;
  ResultCode: Integer;
  NOSTART_Value : String;
begin
  if CurStep = ssDone then
    begin
      NOSTART_Value := GetCommandLineParam('/NOSTART');
      if(NOSTART_Value = 'false') then
        begin
          Filename := ExpandConstant('{app}\{#MyAppExeName}');
          Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
        end
    end;
end;

代码更新。感谢@TLama

function CmdLineParamExists(const Value: string): Boolean;
var
  I: Integer;  
begin
  Result := False;
  for I := 1 to ParamCount do
    if CompareText(ParamStr(I), Value) = 0 then
    begin
      Result := True;
      Break;
    end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  Filename: String;
  ResultCode: Integer;
  NOSTART_Value : String;
  RunApp : Boolean;
begin
  if CurStep = ssDone then
    begin
      RunApp := CmdLineParamExists('/START');
      if(RunApp = True) then
        begin
          Filename := ExpandConstant('{app}\{#MyAppExeName}');
          Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
        end

      // NOSTART_Value := GetCommandLineParam('/START');
      // if(NOSTART_Value = 'true') then
        // begin
          // Filename := ExpandConstant('{app}\{#MyAppExeName}');
          // Exec(Filename, '', '', SW_SHOW, ewNoWait, Resultcode);
        //end
    end;
end;

答案 2 :(得分:-1)

以下内容,易于阅读

; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Install Specialty Programs"
#define MyAppVersion "1.0"
#define MyAppPublisher ""

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{5}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\{#MyAppName}
DisableDirPage=yes
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=P:\_Development\INNO Setup Files\Specialty File Install
OutputBaseFilename=Specialty File Install
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "P:\_Development\INNO Setup Files\Specialty File Install\Files\0.0 - Steps.docx"; DestDir: "c:\support\Specialty Files"; Tasks: V00Step

[Tasks]
Name: "Office2013"; Description: "Running Office 2013"; Flags: checkablealone unchecked
Name: "Office2016"; Description: "Running Office 2016"; Flags: checkablealone unchecked
Name: "V00Step"; Description: "Steps To Follow (Read Me)"; Flags: exclusive

[Run]
Filename: "C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE"; Parameters: """c:\support\Specialty Files\0.0 - Steps.docx"""; Description: "Run if Office 2013 is installed"; Tasks: V00Step AND Office2013
Filename: "C:\Program Files (x86)\Microsoft Office\Office16\WINWORD.EXE"; Parameters: """c:\support\Specialty Files\0.0 - Steps.docx"""; Description: "Run if Office 2016 is installed"; Tasks: V00Step AND Office2016