Allow restricting and configuring Components for multiple installation Types in Inno Setup - components

I have two types of installation in the Components section, like these:
The behaviour I'd like to achieve is:
Installation type "Main1 installation", default type, all components checked but "Main2", which must be disabled.
Then if type "Main2 installation" is selected, component "Main1" must be disabled and unchecked and all "Optional" components unchecked but available to be checked.
This is my code by now:
[Types]
Name: "main1"; Description: "Main1 installation"
Name: "main2"; Description: "Main2 installation"; Flags: iscustom
[Components]
Name: "Main1"; Description: "Main 1"; Types: main1
Name: "Main2"; Description: "Main 2"; Types: main2
Name: "Optional1"; Description: "Optional 1"; Types: main1
Name: "Optional2"; Description: "Optional 2"; Types: main1
Name: "Optional3"; Description: "Optional 3"; Types: main1

You cannot do this with Inno Setup Types. There can only be one custom type, not multiple (two in your case). Types also cannot disable the components.
But you can give up on Types and implement a custom type-like drop down.
Though your requirements are not completely defined, so I cannot give you complete solution (Does the component selection reset when type changes? What does happen with type when you customize the components selection? What happens on upgrade? Etc...).
But this should give you some idea:
[Types]
Name: "dummy"; Description: "dummy"; Flags: iscustom
[Components]
Name: "Main1"; Description: "Main 1"
Name: "Main2"; Description: "Main 2"
Name: "Optional1"; Description: "Optional 1"
Name: "Optional2"; Description: "Optional 2"
Name: "Optional3"; Description: "Optional 3"
[Code]
var
MyTypesCombo: TNewComboBox;
procedure MyTypesComboChange(Sender: TObject);
var
I: Integer;
begin
for I := 0 to WizardForm.ComponentsList.Items.Count - 1 do
begin
WizardForm.ComponentsList.ItemEnabled[I] :=
(I = MyTypesCombo.ItemIndex) or (I >= 2);
WizardForm.ComponentsList.Checked[I] :=
(I = MyTypesCombo.ItemIndex) or ((I >= 2) and (MyTypesCombo.ItemIndex = 0));
end;
end;
procedure InitializeWizard();
var
Delta: Integer;
begin
MyTypesCombo := TNewComboBox.Create(WizardForm);
MyTypesCombo.Parent := WizardForm.TypesCombo.Parent;
MyTypesCombo.Left := WizardForm.TypesCombo.Left;
MyTypesCombo.Top := WizardForm.TypesCombo.Top;
MyTypesCombo.Width := WizardForm.TypesCombo.Width;
MyTypesCombo.Height := WizardForm.TypesCombo.Height;
MyTypesCombo.Style := WizardForm.TypesCombo.Style;
MyTypesCombo.Anchors := WizardForm.TypesCombo.Anchors;
MyTypesCombo.TabOrder := WizardForm.TypesCombo.TabOrder;
MyTypesCombo.Items.Add('Main1 installation');
MyTypesCombo.Items.Add('Main2 installation');
MyTypesCombo.OnChange := #MyTypesComboChange;
MyTypesCombo.ItemIndex := 0;
MyTypesComboChange(nil);
WizardForm.IncTopDecHeight(
WizardForm.ComponentsList, MyTypesCombo.Height + ScaleY(3));
end;

Related

How to uninstall a program mistakenly installed in the "Program Files(x86)" folder and install it anew in the 64-bit "Program Files" folder

I am using innoSetup to create a software installer.
However, by default, innoSetup installs to "Program Files(x86)", which I have mistakenly distributed to my users.
And many users install the software in the x86 directory using a 64-bit Windows environment.
I created an installer for the new version of the software with innoSetup and designed it to install correctly in "Program Files" for 64-bit.
However, the programs already installed in "Program Files(x86)" are not uninstalled and remain.
How can I uninstall them?
A similar question exists in the past on stack overflow, but it did not solve my problem.
I had initially written the following code.
This was installed in the "Program Files(x86)" folder, even when used in a Windows 64-bit environment
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "testApp"
#define MyAppVersion "1.00"
#define MyAppPublisher "taichi"
#define MyAppURL "https://testApp.com/"
#define MyAppExeName "testApp.exe"
[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={{xxx-xxxx-xxxxx-xxx}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\taichi\Desktop
OutputBaseFilename=testAppSetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
[Code]
/////////////////////////////////////////////////////////////////////
function GetUninstallString(): String;
var
sUnInstPath: String;
sUnInstallString: String;
begin
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
/////////////////////////////////////////////////////////////////////
function IsUpgrade(): Boolean;
begin
Result := (GetUninstallString() <> '');
end;
/////////////////////////////////////////////////////////////////////
function UnInstallOldVersion(): Integer;
var
sUnInstallString: String;
iResultCode: Integer;
begin
// Return Values:
// 1 - uninstall string is empty
// 2 - error executing the UnInstallString
// 3 - successfully executed the UnInstallString
// default return value
Result := 0;
// get the uninstall string of the old app
sUnInstallString := GetUninstallString();
if sUnInstallString <> '' then begin
sUnInstallString := RemoveQuotes(sUnInstallString);
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
Result := 3
else
Result := 2;
end else
Result := 1;
end;
/////////////////////////////////////////////////////////////////////
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep=ssInstall) then
begin
if (IsUpgrade()) then
begin
UnInstallOldVersion();
end;
end;
end;
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "C:\Users\taichi\Documents\hold\testAppDevelop\dist\testApp\testApp.exe"; DestDir: "{app}"; Flags: ignoreversion
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: runasoriginaluser nowait postinstall skipifsilent
After modifying the code as follows, the software was installed in Program Files. However, the files in Program Files(x86) were not uninstalled.
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "testApp"
#define MyAppVersion "1.00"
#define MyAppPublisher "taichi"
#define MyAppURL "https://testApp.com/"
#define MyAppExeName "testApp.exe"
[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={{xxx-xxxx-xxxxx-xxx}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\taichi\Desktop
OutputBaseFilename=testAppSetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x64
[Code]
/////////////////////////////////////////////////////////////////////
function GetUninstallString(): String;
var
sUnInstPath: String;
sUnInstallString: String;
begin
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
function GetUninstallString32: string;
var
sUnInstPath: string;
sUnInstallString: String;
begin
Result := '';
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{{A227028A-40D7-4695-8BA9-41DF6A3895C7}_is1'); { Your App GUID/ID }
sUnInstallString := '';
if not RegQueryStringValue(HKLM32, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
/////////////////////////////////////////////////////////////////////
function IsUpgrade(): Boolean;
begin
Result := (GetUninstallString() <> '');
end;
function IsUpgrade32(): Boolean;
begin
Result := (GetUninstallString32() <> '');
end;
/////////////////////////////////////////////////////////////////////
function UnInstallOldVersion(): Integer;
var
sUnInstallString: String;
iResultCode: Integer;
begin
// Return Values:
// 1 - uninstall string is empty
// 2 - error executing the UnInstallString
// 3 - successfully executed the UnInstallString
// default return value
Result := 0;
// get the uninstall string of the old app
sUnInstallString := GetUninstallString();
if sUnInstallString <> '' then begin
sUnInstallString := RemoveQuotes(sUnInstallString);
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
Result := 3
else
Result := 2;
end else
Result := 1;
end;
function UnInstallOldVersion32(): Integer;
var
sUnInstallString: String;
iResultCode: Integer;
begin
// Return Values:
// 1 - uninstall string is empty
// 2 - error executing the UnInstallString
// 3 - successfully executed the UnInstallString
// default return value
Result := 0;
sUnInstallString := GetUninstallString32();
if sUnInstallString <> '' then begin
sUnInstallString := RemoveQuotes(sUnInstallString);
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
Result := 3
else
Result := 2;
end else
Result := 1;
end;
/////////////////////////////////////////////////////////////////////
procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep=ssInstall) then
begin
if (IsUpgrade()) then
begin
UnInstallOldVersion();
end;
end;
begin
UnInstallOldVersion32();
end;
end;
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "C:\Users\taichi\Documents\hold\testAppDevelop\dist\testApp\testApp.exe"; DestDir: "{app}"; Flags: ignoreversion
[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: runasoriginaluser nowait postinstall skipifsilent

Multiple Inno Setup Types that have optional Components

I am trying to create a Inno Setup installer (with Inno Setup 6.2.0) that has multiple setup Types where more than one can have optional Components (as well as fixed components). For example, suppose I want to have the following setup types:
Instructor
Student
If the "Instructor" setup type is selected, I would like to have an "Instructor - Fixed" component (which must be installed), plus two optional components "Instructor- Optional 1" and "Instructor - Optional 2".
Similarly for the "Student" setup type, I would like a fixed component plus a couple of optional components.
Below is the starting point for my experiments:
[Types]
Name: TYPE_INSTRUCTOR ; Description: "Instructor" ;
Name: TYPE_STUDENT ; Description: "Student" ;
[Components]
Name: COMP_INSTRUCTOR ; Description: "Instructor" ; Types: TYPE_INSTRUCTOR
Name: COMP_INSTRUCTOR\FIXED ; Description: "Instructor - Fixed" ; Types: TYPE_INSTRUCTOR ; Flags: fixed
Name: COMP_INSTRUCTOR\OPTIONAL_1 ; Description: "Instructor - Optional 1" ; Types: TYPE_INSTRUCTOR
Name: COMP_INSTRUCTOR\OPTIONAL_2 ; Description: "Instructor - Optional 2" ; Types: TYPE_INSTRUCTOR
Name: COMP_STUDENT ; Description: "Student" ; Types: TYPE_STUDENT
Name: COMP_STUDENT\FIXED ; Description: "Student - Fixed" ; Types: TYPE_STUDENT ; Flags: fixed
Name: COMP_STUDENT\OPTIONAL_1 ; Description: "Student - Optional 1" ; Types: TYPE_STUDENT
Name: COMP_STUDENT\OPTIONAL_2 ; Description: "Student - Optional 2" ; Types: TYPE_STUDENT
[Files]
Source: "InstFixed.txt" ; DestDir: {app} ; Components: COMP_INSTRUCTOR\FIXED
Source: "InstOpt1.txt" ; DestDir: {app} ; Components: COMP_INSTRUCTOR\OPTIONAL_1
Source: "InstOpt2.txt" ; DestDir: {app} ; Components: COMP_INSTRUCTOR\OPTIONAL_2
Source: "StuFixed.txt" ; DestDir: {app} ; Components: COMP_STUDENT\FIXED
Source: "StuOpt1.txt" ; DestDir: {app} ; Components: COMP_STUDENT\OPTIONAL_1
Source: "StuOpt2.txt" ; DestDir: {app} ; Components: COMP_STUDENT\OPTIONAL_2
I have tried a few different things, but nothing has succeeded in achieving what I need. I have tried:
Adding Flags: iscustom to both setup types (my thinking was to indicate that both are customisable). However, Inno Setup only seems to allow for one customisable type.
Making just one of the setup type to have Flags: iscustom (e.g. adding it to TYPE_INSTRUCTOR). However, that does not work as I would like, because I can then end up with invalid combinations, e.g. I can select a mixture of Instructor and Student components.
The only way I can think to get around this is to have setup types for every possible combination. That would not be practical (this example is not my real problem, just a simple case to illustrate it, I would end up with a very large list of setup types).
Thank you in advance for any workable solutions.
That's not possible. At least not without some heavy customization with Pascal Scripting.
Way easier is to drop the Types altogether and use two top-level mutually-exclusive components and couple of optional subcomponents:
[Types]
Name: "custom"; Description: "Custom installation"; Flags: iscustom
[Components]
Name: "intructor"; Description: "Instructor"; Flags: exclusive
Name: "intructor\opt1"; Description: "Optional 1"
Name: "intructor\opt2"; Description: "Optional 2"
Name: "student"; Description: "Student"; Flags: exclusive
Name: "student\opt1"; Description: "Optional 1"
Name: "student\opt2"; Description: "Optional 2"

Change setup types in Inno Setup installer, depending on whether it's New Install or Update?

I created an installer with Inno Setup to install a database. My script-writing skills are quite basic. Now I need to offer updates, and need the installer to:
check if there is an existing installation;
check if an existing installation is older;
offer Update as option if there is an existing installation, or offer Admin or General database (new installation) as options if not.
I have pieced the code below together, which shows the three options in a dropdown/combobox. I cannot figure out how to change the options offered in the combobox on the wpSelectComponents page.
[Code]
function InitializeSetup(): Boolean;
var
OldVersion, NewVersion: String;
begin
Result := True;
//Check in the registry for the uninstaller of PME Database. Compare version, exit if installed version is the same or newer.
if RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1') then
begin
RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1', 'DisplayVersion', OldVersion)
NewVersion := '{#MyAppVersion}'
If NewVersion < OldVersion then
begin
MsgBox(('This version (' + NewVersion + ') is older than the installed version (' + OldVersion +') - setup will close.'), mbError, MB_Ok)
Result := False;
exit;
end;
If NewVersion = OldVersion then
begin
MsgBox(('This version (' + NewVersion + ') is the same as the installed version - setup will close.'), mbError, MB_Ok)
Result := False;
exit;
end;
If NewVersion > OldVersion then
begin
if MsgBox(('The database will be updated from version ' + OldVersion + ' to version ' + NewVersion + '.' + chr(13) + chr(13) + 'Continue?'), mbInformation, MB_YesNo) = idNo then
begin
Result := False;
exit;
end;
end;
end;
...more code, to check Windows / Office versions...
[Code]
Procedure CurPageChanged(CurPage: Integer);
begin
if CurPage = wpSelectComponents then
begin
if RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1') then
begin
//Do something: only show Update as combobox option - HOW???
end else begin
//Do something: only show Admin and General as combobox options - HOW???
end;
end;
end;
[Types]
Name: "Other1"; Description: "General Database"; Languages: en
Name: "Admin1"; Description: "Administrator Database"; Languages: en
Name: "Update1"; Description: "Database update"; Languages: en
Name: "Other2"; Description: "Base de Données Générale"; Languages: fr
Name: "Admin2"; Description: "Base de Données de L'administrateur"; Languages: fr
Name: "Update2"; Description: "Mise à jour de Base de Données"; Languages: fr
Name: "Other3"; Description: "Base de Dados Geral"; Languages: pt
Name: "Admin3"; Description: "Base de Dados do Administrador"; Languages: pt
Name: "Update3"; Description: "Atualização da Base de Dados"; Languages: pt
[Components]
Name: "General"; Description: "General"; Types: other1 other2 other3; Flags: fixed disablenouninstallwarning
Name: "Admin"; Description: "Admin"; Types: admin1 admin2 admin3; Flags: fixed disablenouninstallwarning
Name: "Update"; Description: "Update"; Types: update1 update2 update3; Flags: fixed disablenouninstallwarning
[Files]
; Database files.
Source: "C:\PME SETUP\pme versions\v2.02\PME Database.accde"; DestDir: "{app}"; Components: admin general update
; Data files are ONLY copied for a new installation of the central administrator database.
Source: "C:\PME SETUP\pme versions\v2.02\PME Data Storage.accdb"; DestDir: "{app}"; Components: admin
Source: "C:\PME SETUP\pme versions\v2.02\PME Data Storage.accdb"; DestDir: "{app}\System Files"; Components: admin
Source: "C:\PME SETUP\pme versions\v2.02\PME Data Storage.accdb"; DestDir: "{app}\Exchange"; Components: admin
...more follows for different component-combinations...
You are looking for Check parameter:
[Types]
Name: "Other"; Description: "General Database"; Check: not IsUpdate
Name: "Admin"; Description: "Administrator Database"; Check: not IsUpdate
Name: "Update"; Description: "Database update"; Check: IsUpdate
[Code]
function IsUpdate: Boolean;
begin
Result :=
RegKeyExists(HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{pmedatabase201}}_is1') and
/*IsNewer*/;
end;
Note that you should check HKEY_LOCAL_MACHINE too to determine, if the application is installed already.

Inno setup: don't show option if it is not checked

After looking at this example Inno Setup: Function to select a component I've added another option to my code but what I'm trying to do (and I don't know if it is possible) is that if in the components section an option hasn't been marked, I don't want it to appear in Page1.Add('help'); or Page1.Add('readme\de');
[Setup]
AppName=My Program
AppVerName=My Program v.1.2
DefaultDirName={pf}\My Program
[Types]
Name: full; Description: Full installation
Name: compact; Description: Compact installation
Name: custom; Description: Custom installation; Flags: iscustom
[Components]
Name: program; Description: Program Files; Types: full compact custom; Flags: fixed
Name: help; Description: Help File; Types: full
Name: readme; Description: Readme File; Types: full
Name: readme\en; Description: English; Flags: exclusive
Name: readme\de; Description: German; Flags: exclusive
[Code]
var
Page1: TInputOptionWizardPage;
Procedure BackupCheckCreate();
var
StaticText: TNewStaticText;
begin
Page1 := CreateInputOptionPage(wpReady, 'Optional Actions Test',
'Which actions should be performed?',
'Please select all optional actions you want to be performed, then click Next.', False, False);
Page1.Add('help');
Page1.Add('readme\de');
Page1.Values[0] := False;
Page1.Values[1] := False;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
Result := (PageID = Page1.ID) and (not IsComponentSelected('help') and not IsComponentSelected('readme\de'));
end;
procedure InitializeWizard();
begin
BackupCheckCreate();
end;
There is no easy way to hide items from TInputOptionWizardPage or generally any custom page at this time. So conditional showing certain check box items on your options page by selected components is not an easy task. So before digging into some hacky ways I would suggest you another way.
From the caption of the page you are creating it looks like you need the [Tasks] section. This section allows you to create additional task check boxes with simple binding to the selected components. Check this example:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Types]
Name: full; Description: Full installation
Name: compact; Description: Compact installation
Name: custom; Description: Custom installation; Flags: iscustom
[Components]
Name: main; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: backup; Description: "Backup DB"; Types: full
Name: restore; Description: "Restore DB"; Types: full
[Tasks]
; if "backup" component is selected, these two tasks appear
Name: backuptask1; Description: "Backup 1"; GroupDescription: "Backup Tasks:"; Components: backup
Name: backuptask2; Description: "Backup 2"; GroupDescription: "Backup Tasks:"; Components: backup
; if "restore" component is selected, these two tasks appear
Name: restoretask1; Description: "Restore 1"; GroupDescription: "Restore Tasks:"; Components: restore
Name: restoretask2; Description: "Restore 2"; GroupDescription: "Restore Tasks:"; Components: restore

I wanted to add my setup at user/My Documents for every user using the inno setup but its not working for me

I wanted to add my setup at user/My Documents for every user using the inno setup but its not working for me.
Here i provide u my iis file.
Thanks in advance.
Please help me out.
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Testing"
#define MyAppVersion "1.0"
#define MyAppPublisher "Test"
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "testing.exe"
[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={{200DC169-9647-4295-91B4-B1D1D8482B82}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
;DefaultDirName={userdocs}\test
DefaultDirName={code:DefDirRoot}\test
DisableDirPage=yes
DefaultGroupName=test
DisableProgramGroupPage=yes
AllowNoIcons=yes
LicenseFile=C:\Users\abc\Desktop\final product\licence.txt
OutputDir=C:\Users\abc\Documents\test
OutputBaseFilename=VL-PI Setup
SetupIconFile=C:\Users\abc\Downloads\clientcommentsveryimp\CORRECTIONS_TO_INSTALLER_BUGS\CORRECTIONS_TO_INSTALLER_BUGS\Icon\icon.ico
Compression=lzma
SolidCompression=yes
PrivilegesRequired=none
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
[Dirs]
Name: "{app}\Graphics"
Name: "{app}\lib"
[Files]
Source: "C:\test work\agriculture project requirments\jre-6u2-windows-i586-p.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall;
Source: "D:\final product\30-01-2013\test.exe"; DestDir: "{app}"; Flags: ignoreversion;
Source: "C:\Users\test\Desktop\final product\Graphics\*"; DestDir: "{app}\Graphics"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "C:\Users\test\Desktop\final product\lib\*"; DestDir: "{app}\lib"; Flags: ignoreversion recursesubdirs createallsubdirs
[Icons]
Name: "{group}\VL-PI"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:uninstallProgram,VL-PI}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}";
Tasks: quicklaunchicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}";check:InitializeSetup; Flags: nowait postinstall skipifsilent
[Code]
function Install_JavaFrameWork() : Boolean;
var
hWnd: Integer;
ResultCode: Integer;
dotnetRedistPath: string;
outVar : string;
begin
dotnetRedistPath:= ExpandConstant('{tmp}\jre-6u2-windows-i586-p.exe');
try
if Exec(dotnetRedistPath,'', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// ResultCode contains the exit code
case ResultCode of
// 1641 The requested operation completed successfully. The system will be restarted so the changes can take effect.
// 3010 The requested operation is successful. Changes will not be effective until the system is rebooted.
1641:
begin
Result := true;
end
3010, 0:
begin
Result := false;
end else // -> case default
begin
Result := true;
end
end;
end else
begin
//handle failure if necessary; ResultCode contains the error code
Result := false;
end;
except
ShowExceptionMessage;
end;
end;
function InitializeSetup(): Boolean;
var
ErrorCode: Integer;
JavaInstalled : Boolean;
Result1 : Boolean;
Versions: TArrayOfString;
I: Integer;
begin
if RegGetSubkeyNames(HKLM, 'SOFTWARE\JavaSoft\Java Runtime Environment', Versions) then
begin
for I := 0 to GetArrayLength(Versions)-1 do
if JavaInstalled = true then
begin
//do nothing
end else
begin
if ( Versions[I][2]='.' ) and ( ( StrToInt(Versions[I][1]) > 1 ) or ( ( StrToInt(Versions[I][1]) = 1 ) and (
StrToInt(Versions[I][3]) >= 6 ) ) ) then
begin
JavaInstalled := true;
end else
begin
JavaInstalled := false;
end;
end;
end else
begin
JavaInstalled := false;
end;
//JavaInstalled := RegKeyExists(HKLM,'SOFTWARE\JavaSoft\Java Runtime Environment\1.9');
if JavaInstalled then begin
Result := true;
end
else begin
if FileExists(ExpandConstant('{tmp}\jre-6u2-windows-i586-p.exe')) then
begin
Log('File exists');
Result1 := MsgBox('This program requires Java Runtime Environment version 1.6 or newer.Do you want to install it now?',
mbConfirmation, MB_YESNO) = idYes;
if Result1 = false then begin
Result:=true;
end
else begin
Install_JavaFrameWork;
Result:=true;
end;
end else
begin
Result:=true;
end;
end;
end;
An admin setup should never try and write to the user's profiles as they aren't guaranteed to be the user you expect or even accessable from that machine.
You're currently using PrivilegesRequired=none so it will not switch user, but that will stop you from installing Java for some users.
You should use PrivilegesRequired=admin for normal installations or PrivilegesRequired=lowest for user specific installations.

Resources