4
votes

I am new to Inno Setup and I have already read the documentation. Now I know that Inno Setup can accept different/custom parameter and could be processed via Pascal script. But the problem is, I don't know how to write in Pascal.

I am hoping I could get help about the coding.

I'd like to pass /NOSTART parameter to my setup file which while tell the setup to disable(uncheck) the check mark on "Launch " and if /NOSTART is not provided, it it will enable(check) the check mark "Launch "

enter image description here

or if possible, that Launch page is not required and do everything via code.

3

3 Answers

7
votes

Since you can't imperatively modify flags for section entries and directly accessing the RunList would be quite a dirty workaround, I'm using for this two postinstall entries, while one has no unchecked flag specified and the second one has. So, the first entry represents the checked launch check box and the second one unchecked launch check box. Which one is used is controlled by the Check parameter function, where is checked if a command line tail contains /NOSTART parameter.

Also, I've used a little more straightforward function for determining if a certain parameter is contained in the command line tail. It uses the CompareText function to compare text in a case insensitive way. You can replace it with CompareStr function, if you want to compare the parameter text in a case sensitive way. Here is the script:

[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;
3
votes

and so a little research read and read .. i got my answer.

here's my code (except the "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;

a code update. Thanks to @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;
-1
votes

How about the following, easy to read

; 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