4

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

我希望我能得到有关编码的帮助。

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

在此处输入图像描述

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

4

3 回答 3

7

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

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

[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;
于 2013-01-19T14:00:52.697 回答
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;
于 2013-01-18T07:15:38.717 回答
-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

于 2020-03-19T08:23:57.220 回答