I am a noob in coding trying to make an installer with Inno Setup.
Basically I am trying to merge two codes I found on this site: one for having a /VERYSILENT installation, and another one for quitting the setup if a registry key is not found.
I already know I can't have two InitializeSetup functions, and if I got it right, I must be merging them using event attributes.
I already tried merging the two functions using only one "function InitializeSetup" in various ways, but usually only one code of the two works, the other seems invisible.
I tried also using the event attribute command, but I don't know how to properly use it.
This is my initial code with the two InitializeSetup functions:
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
type
HINSTANCE = THandle;
function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
lpParameters: string; lpDirectory: string; nShowCmd: Integer): HINSTANCE;
external 'ShellExecute{#AW}@shell32.dll stdcall';
//First one
function InitializeSetup: Boolean;
begin
Result := WizardSilent;
if not Result then
begin
if ShellExecute(0, '', ExpandConstant('{srcexe}'), '/VERYSILENT', '',
SW_SHOW) <= 32
then
Result := True;
end;
end;
//Second one
function InitializeSetup: Boolean;
begin
Result := True;
if not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion... etc. etc.') then
begin
Result := False;
end;
end;
Thanks in advance to whoever can help me.
EDIT
This is the code with the event attributes features that I put together from the example in the link Martin Prikryl gived me:
#ifdef UNICODE
#define AW "W"
#else
#define AW "A"
#endif
type
HINSTANCE = THandle;
function ShellExecute(hwnd: HWND; lpOperation: string; lpFile: string;
lpParameters: string; lpDirectory: string; nShowCmd: Integer): HINSTANCE;
external 'ShellExecute{#AW}@shell32.dll stdcall';
<event('InitializeSetup')>
function InitializeSetup1: Boolean;
begin
Result := WizardSilent;
if not Result then
begin
if ShellExecute(0, '', ExpandConstant('{srcexe}'), '/VERYSILENT', '',
SW_SHOW) <= 32
then
Result := True;
end;
end;
<event('InitializeSetup')>
function InitializeSetup2: Boolean;
begin
Result := True;
if not RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion... etc. etc.') then
begin
Result := False;
end;
end;
Seems it's working now.