Inno Setup, show a msgbox on the folder selection step - inno-setup

I am trying to display a message box only when the user reach the folder selection page, here are the actual code that display the message box at the beginning of the setup:
[code]
var ApplicationPath: string;
function GetAppPath(Param: String): String;
begin
RegQueryStringValue(HKLM, 'SOFTWARE\XXX\XXX', 'Install Dir', ApplicationPath)
if ApplicationPath = '' then
begin
MsgBox('Install folder non found', mbError, MB_OK);
result:=ApplicationPath;
end
else
MsgBox('Install folder found in "' + ApplicationPath + '". NOTE: close the program before proceeding.', mbInformation, MB_OK);
result:=ApplicationPath;
end;
end.
I need something like:
If (PageId = wpSelectDir) then...
[run the above code]
but really I don't know how, thanks for your help.

The ideal event for this is the CurPageChanged. You can use it this way to run a code, when the select directory page is shown:
[Code]
procedure CurPageChanged(CurPageID: Integer);
var
AppPath: string;
begin
if (CurPageID = wpSelectDir) then
begin
// this will query the string value in registry; if that succeed and the
// value is read, then the message box about success is shown, otherwise
// the error message box about failure is shown
if RegQueryStringValue(HKLM, 'SOFTWARE\XXX\XXX', 'Install Dir', AppPath) then
MsgBox('Installation folder found...', mbInformation, MB_OK)
else
MsgBox('Installation folder not found...', mbError, MB_OK);
end;
end;

Related

Check installation path for spaces and special symbol in Inno Setup

I cannot find a solution for checking the user selected path to be without any spaces or special characters.
Can you help me?
You can check for space like this:
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
Dir: string;
Msg: string;
begin
Result := True;
if CurPageID = wpSelectDir then
begin
Dir := WizardForm.DirEdit.Text;
if Pos(' ', Dir) > 0 then
begin
Msg := 'The path cannot contain spaces';
if WizardSilent then Log(Msg)
else MsgBox(Msg, mbError, MB_OK);
Result := False;
end;
end;
end;
You may consider using SuppressibleMsgBox function:
What does it mean that message boxes are being suppressed in Inno Setup?

Inno Setup: Create application valid for one year

I test my software with new code.
const MY_EXPIRY_DATE_STR = '20131112'; //Date format: yyyymmdd
function InitializeSetup(): Boolean;
var
ErrorCode: Integer;
begin
//If current date exceeds MY_EXPIRY_DATE_STR then return false and exit Installer.
result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), MY_EXPIRY_DATE_STR) <= 0;
if not result then
begin
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end
if (MsgBox('Autocad will compulsory closed,so please save your drawings and then press OK', mbConfirmation, MB_OK) = IDOK) then
begin
ShellExec('open', 'taskkill.exe', '/f /im acad.exe','', SW_HIDE, ewNoWait, ErrorCode);
ShellExec('open', 'tskill.exe', ' ACAD', '', SW_HIDE, ewNoWait, ErrorCode);
Result := True;
end
else
begin
Result := False;
end;
end;
The issue is the setup show the error message (Now it's forbidden to install this program) but it continue install. I want it exit the installer.
You're forgetting to return from the function when your expiry condition is met.
This
if not result then
begin
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
end
should be:
if not Result then
begin
MsgBox('Now it''s forbidden to install this program', mbError, MB_OK);
Exit;
end;
Without the Exit, the following statements execute with the possibility of setting Result to 'True' again.
Notice also the formatting. If you had it right, there is a good chance that you wouldn't be asking this question.

call RegQueryDWordValue to get office Excel Version using inno Setup installer

How do I get installed Version of MS office Excel from registry using inno Script? i tried bellow code,it gives 'Key not found' but it exist
function InitializeSetup(): Boolean;
var
CurVer: Cardinal;
key: string;
if RegQueryDWordValue(HKCR, 'Excel.Application\CurVer\','Default', CurVer) then
begin
// Successfully read the value
MsgBox('Excel Version: ' + IntTOStr(CurVer),mbInformation, MB_OK);
end else begin
MsgBox('Key not found',mbInformation, MB_OK);
end;
end;
changed RegQueryDWordValue to RegQueryStringValue
function InitializeSetup(): Boolean;
var
CurVer: Cardinal;
key: string;
begin
//if RegQueryDWordValue(HKCR, 'Excel.Application\\CurVer\\','', CurVer) then
if RegQueryStringValue(HKCR, 'Excel.Application\CurVer\','', key) then
begin
// Successfully read the value
MsgBox('Excel Version: ' + key,mbInformation, MB_OK);
end else begin
MsgBox('Excel Not installed',mbInformation, MB_OK);
end;
end;
Remove the trailing backslash.
Also, the (Default) value in RegEdit is the one with no name:
if RegQueryDWordValue(HKCR, 'Excel.Application\CurVer','', CurVer) then

Inno Setup: If the specified path does not already exist on the user's system, it will be created automatically:(

If the specified path does not already exist on the user's system, it will be created automatically. But I dont want it to crate automatically. The setup install a notepad++plugin, however if notepad++ is not installed on the user system, it creates a notepad++ file. I want to implement a code which ask user "notepad++ is not installed on your system do you wish to continue?"
I am new in innosetup compiler, so I need help about the code part. I found an example on the internet., but that is not the exact code that I want. So please help me..
function NextButtonClick(PageId: Integer): Boolean;
begin
Result := True;
if (PageId = wpSelectDir) and not FileExists(ExpandConstant('{app}\yourapp.exe')) then begin
MsgBox('YourApp does not seem to be installed in that folder. Please select the correct folder.', mbError, MB_OK);
Result := False;
exit;
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := True;
if (CurPageID = wpSelectComponents) and IsComponentSelected('notepad_plugin') then
if not DirExists('/*your directory*/') then
begin
MsgBox('Component Selection:' #13#13 'Notepad++ could not be found on your system.', mbInformation, MB_OK);
Result := False;
end;
end;

Inno Setup - Display MessageBox to run additional file

I am new to Inno Setup and having difficulty find this answer...
I have included a DirectX9 setup file in the installer, but I want to display a MessageBox to the user to ask "Do you want to install DirectX9?" that is done before the regular installation of my game... if he says yes, then I want to run this additional file that I included, but otherwise just proceed to install the game.
The following code will run just before the installation begins. It asks for confirmation from the user and then runs "InstallDirectX.exe" (which must be available to the installer).
[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: integer;
begin
if (msgbox('Do you want to install DirectX ?', mbConfirmation, MB_YESNO) = IDYES) then
begin
if Exec(ExpandConstant('InstallDirectX.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
MsgBox('Everything is proceeding according to plan', mbInformation, MB_OK);
end
else
begin
// handle failure if necessary; ResultCode contains the error code
MsgBox('Something went horribly wrong', mbError, MB_OK);
end;
end;
end;
If you want to display message box when installation finished, you can use this code:
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
begin
if CurStep = ssPostInstall then
begin
if (msgbox('Do you want to install DirectX ?', mbConfirmation, MB_YESNO) = IDYES) then
begin
if Exec(ExpandConstant('{src}\dxwebsetup.exe'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
MsgBox('Installing DirectX completed', mbInformation, MB_OK);
end
else
begin
MsgBox('Installing Error', mbError, MB_OK);
end;
end;
end;
end;

Resources