Hardcode startup switches into INNO Setup script and retrieve them in [code] in InnoIDE - inno-setup

When I compile and then run my Inno script, I want to parse hard coded command line switches. So, instead of running my script as c:\myInstall.exe /myswitch I want to run it via IDE and have this switch included at the start here
With this code, I want to retrieve this switch in ParamStr(x)
function MyParams(param: String): string;
begin
MsgBox(ParamStr(3), mbError, MB_OK);
Result := MyParameter;
end;
{Parameter Detection--end}
function InitializeSetup(): Boolean;
begin
MyParams('XXX');
end;

I found a tool, which does this for you - you can set DEBUG variables if you use
Inno Script Studio

Related

Run application after click on the Finish button (not after install)

I have a setup for installing my application, and I need to run the application after successfully installing. I used postinstall to do this.
but it shows a checkbox and the user can uncheck it. I need to run the application without asking because of it kinda service which needs to runs at startup. if the user unchecked it he needs to restart the PC to launch.
So I can use the Filename: "{app}\myapp.exe" code without any flags in the Run section to launch the application but the problem is, It runs immediately after installing not after the finish button clicked.
The first issue is my application has an instruction window. it shows up at the launch so the setup window goes to the back. And the second issue is my application does not allow terminating unless uninstall becouse it need to run in the background. Setup waiting to process end to finish.
Is there any way to run the application after the finish button click in inno setup?
Simplifying the answer from Run Files and Programs according to custom checkboxes after clicking on Finish Button in Inno Setup, you can use a code like this:
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
Path, Msg: string;
begin
if CurPageID = wpFinished then
begin
Path := ExpandConstant('{app}\MyProg.exe');
if ExecAsOriginalUser(Path, '', '', SW_SHOW, ewNoWait, ResultCode) then
begin
Log('Executed MyProg');
end
else
begin
Msg := 'Error executing MyProg - ' + SysErrorMessage(ResultCode);
MsgBox(Msg, mbError, MB_OK);
end;
end;
Result := True;
end;
Replace ExecAsOriginalUser with Exec, if you want to run the program with elevated/Administrator privileges (if the installer uses them at all).
Add code section to your script like this:
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
begin
if CurStep = ssDone then
Exec(ExpandConstant('{app}\MyProg.exe'), '', '', SW_SHOW, ewNoWait, ResultCode);
end;
It will be triggered only on a success installation.
Use ExecAsOriginalUser instead of Exec if you don't want the exe run as admin.

Inno Setup: Checking existence of a file in 32-bit System32 (Sysnative) folder

I have a sys file in the System32\Drivers folder called gpiotom.sys (custom sys file). My my application is strictly 32-bit compatible only, so my installer runs in 32-bit mode. My script needs to find if this sys file exists or not.
I used the FileExists function explained on the below post but it does not work since it only works for 64-bit application only:
InnoSetup (Pascal): FileExists() doesn't find every file
Is there any way I can find if my sys file exists or not in a 32-bit mode?
Here is my code snippet in Pascal Script language:
function Is_Present() : Boolean;
begin
Result := False;
if FileExists('{sys}\driver\gpiotom.sys') then
begin
Log('File exists');
Result := True;
end;
end;
In general, I do not think there is any problem running an installer for 32-bit application in 64-bit mode. Just make sure you use 32-bit paths where necessary, like:
[Setup]
DefaultDirName={pf32}\My Program
Anyway, if you want to stick with 32-bit mode, you can use EnableFsRedirection function to disable WOW64 file system redirection.
With use of this function, you can implement a replacement for FileExists:
function System32FileExists(FileName: string): Boolean;
var
OldState: Boolean;
begin
if IsWin64 then
begin
Log('64-bit system');
OldState := EnableFsRedirection(False);
if OldState then Log('Disabled WOW64 file system redirection');
try
Result := FileExists(FileName);
finally
EnableFsRedirection(OldState);
if OldState then Log('Resumed WOW64 file system redirection');
end;
end
else
begin
Log('32-bit system');
Result := FileExists(FileName);
end;
if Result then
Log(Format('File %s exists', [FileName]))
else
Log(Format('File %s does not exists', [FileName]));
end;

Execute different BLOCK of commands in Inno Setup Run section based on Windows version

I know there is already question Execute different command in Inno Setup Run section based on Windows version with very good answer.
My question is how to perform different blocks of commands for different target Windows versions. My problem is that I have ~10-15 commands that need to perform if target version is Windows 7 and the ~same amount of different commands for Windows 8 or above.
Is it possible to avoid the need to add ; OnlyBelowVersion: 6.2 after each command needed for first case and ; MinVersion: 6.2 after each command in the second block?
I know there is preprocessor conditions "#if", #else and #endif but that of course works only at compilation time
The question and answers Determine Windows version in Inno Setup although may look similar to this question are NOT answering it. I know how to determine Windows version in Inno Setup. I also know about those ; MinVersion: 6.2 and ; OnlyBelowVersion: 6.2 options. I am asking if it is possible to specify a block of commands (10-15 commands) and apply that option to entire block, not to each and every command individually.
The goal is not to avoid "cryptic version numbers" but to avoid repeating the same condition many times. And to avoid risk of forgetting it when block will grow over the time.
The solution that I found so far is to use CurStepChanged procedure:
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
if IsWindows8OrLater() then
MsgBox('Running on Windows 8 Or Later', mbInformation, MB_OK)
{ 15 comands or call of W8-specific procedure goes here }
else begin
MsgBox('Running on Windows 7', mbInformation, MB_OK);
{ 15 comands or call of W7-specific procedure goes here }
end;
end;
But it looks a bit ugly to me...
There are no block-control features in the .iss file.
All you can do, to avoid repeating the cryptic version numbers, is to define a preprocessor variable like:
#define Windows8AndNewer "MinVersion: 6.2"
#define Windows7AndOlder "OnlyBelowVersion: 6.2"
[Run]
Filename: "Windows8-Command1.exe"; {#Windows8AndNewer}
Filename: "Windows8-Command2.exe"; {#Windows8AndNewer}
Filename: "Windows7-Command1.exe"; {#Windows7AndOlder}
Filename: "Windows7-Command2.exe"; {#Windows7AndOlder}
The only other way is to reimplement the [Run] section in the [Code] using the Exec function:
procedure Run(FileName: string);
var
ResultCode: Integer;
begin
Exec(FileName, '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
{ some error checking }
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
if GetWindowsVersion() >= $06020000 then
begin
Log('Running on Windows 8 or later');
Run('Windows8-Command1.exe');
Run('Windows8-Command2.exe');
end
else
begin
Log('Running on Windows 7 or older');
Run('Windows7-Command1.exe');
Run('Windows7-Command2.exe');
end;
end;
end;

Retrieve environment variable using RegQueryStringValue in Inno Setup

I am trying to retrieve an environment variable during installation using RegQueryStringValue,
I am using the following code
[Setup]
DefaultGroupName="{code:GetPath}"
[Code]
function GetPath(Value: String): String;
var
OrigPath: string;
begin
if RegQueryStringValue(HKLM, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'GCC', OrigPath) then
Result := OrigPath;
end;
But the installer gives me an error during installation,
Can someone tell me why or what I can use instead?
In the case of this question, you're trying to use DefaultGroupName instead of DefaultDirName which is causing the errors.

Inno Setup Script - running exe before installing

I wanna run an application before installing and I'm using this code on Inno Setup Script(Pascal):
function InitializeSetup():boolean;
var
ResultCode: integer;
begin
// Launch Notepad and wait for it to terminate
if ExecAsOriginalUser('{src}\MyFolder\Injector.exe', '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
end
else begin
// handle failure if necessary; ResultCode contains the error code
end;
// Proceed Setup
Result := True;
end;
When I'm using "{win}\notepad.exe", It works but when I use "{src}\MyFolder\Injector.exe", Setup doesn't open my program and continues install.
Note : Injector has app.manifest which has 'requireAdministrator'. However this application should be run as administrator.
So what's wrong?
You need to use the ExpandConstant function when using values such as {src} in code.
However, InitializeSetup is also too early to run installation tasks. You should move this code into CurStepChanged(ssInstall).
Also, if it requires admin permissions it must be run with Exec, not ExecAsOriginalUser.
This May work for you... I believe that this problem is because of spaces in the entire path..that should overcome with double quoting the path...
Exec('cmd.exe','/c "'+ExpandConstant('{src}\MyFolder\Injector.exe')+'"', '',SW_SHOW,ewWaitUntilTerminated, ResultCode);
cheers..

Resources