I have the following lines:
[Run]
Filename: "{app}\MyApp.exe"; Flags: postinstall nowait
I would like my app to get started without showing a checkbox (which would disallow the user to do so).
Can somebody show me how, please? Thank you.
There are few options I can think of. The first one is to run your application from the [Code]
section of your script, the second one is to disable that check box for your [Run]
section entry and the third one is to hide the RunList
.
I would personally prefer this way, because it's more straightforward than adding a check box and hiding it later on. You will remove your current [Run]
section entry and call one of the following functions from the NextButtonClick
event method when its CurPageID
parameter equals to wpFinished
, which indicates the Finish button click:
Exec
- executes the specified executable or batch file, using the same credentials as Setup/Uninstall.ExecAsOriginalUser
- executes the specified executable or batch file, using the (normally non-elevated) credentials of the user that started Setup initiallyShellExec
- opens the specified file or performs another action specified by Verb, using the same credentials as Setup/Uninstall.ShellExecAsOriginalUser
- opens the specified file or performs another action specified by Verb, using the (normally non-elevated) credentials of the user that started Setup initially.Because you haven't used the runascurrentuser
nor shellexec
flags, the setup internally calls a function similar to this:
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
begin
Result := True;
if CurPageID = wpFinished then
ExecAsOriginalUser(ExpandConstant('{app}\MyApp.exe'), '', '',
SW_SHOWNORMAL, ewNoWait, ResultCode);
end;
One weakness of this solution is that the program would be executed even if the restart is requested by the setup. To workaround a missing possibility to determine this request we can check if the YesRadio
is visible (it is the Yes, restart the computer now radio button) and selected, which means that the user was asked to restart the computer and confirmed it. Here is the version considering the restart request:
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
begin
Result := True;
// if the "Finish" button was clicked and "Yes, restart the computer now"
// radio button was either not visible or not selected that time, then...
if (CurPageID = wpFinished) and ((not WizardForm.YesRadio.Visible) or
(not WizardForm.YesRadio.Checked))
then
ExecAsOriginalUser(ExpandConstant('{app}\MyApp.exe'), '', '',
SW_SHOWNORMAL, ewNoWait, ResultCode);
end;
Another option is to disable the check box. The user will see that the application is going to be executed, but won't be able to do anything against it (except killing the setup from Task Manager, of course). This time you will keep your [Run]
section entry as it, but modify the RunList
from the [Code]
section:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName=My Program
[Files]
Source: "MyApp.exe"; DestDir: "{app}"
[Run]
Filename: "{app}\MyApp.exe"; Flags: postinstall nowait
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
// you must do this as late as possible, because the RunList is being modified
// after installation; so this will check if there's at least one item in the
// RunList and then set to the first item (indexing starts at 0) Enabled state
// to False
if (CurPageID = wpFinished) and (WizardForm.RunList.Items.Count > 0) then
WizardForm.RunList.ItemEnabled[0] := False;
end;
This will, contrary to the second option, do what you asked for. It will keep the check box hidden, or to be more precise, it will hide the whole RunList
, so if you were having more than one entry in the [Run]
section with the postinstall
flag specified, it won't be seen as well:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName=My Program
[Files]
Source: "MyApp.exe"; DestDir: "{app}"
[Run]
Filename: "{app}\MyApp.exe"; Flags: postinstall nowait
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then
WizardForm.RunList.Visible := False;
end;
Works on version 5.5.7
Add the following code if you want to open a website automatically
[Code]
procedure CurPageChanged(CurPageID: Integer);
var
ErrorCode : Integer ;
begin
if CurPageID = wpFinished then
ShellExecAsOriginalUser('', ExpandConstant('http:\\www.google.pt'), '', '',SW_SHOWNORMAL, ewNoWait, ErrorCode);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With