How to change defaultdirname before installation in Inno Setup?

I want to change the defaultdirname parameter in ssInstall part. How can i do this? Is there a function for setting the [Setup] parameters.

+4
source share
3 answers

The following global objects are available: MainForm of type TMainForm, WizardForm of type TWizardForm and UninstallProgressForm of type TUninstallProgressForm and one special constant: crHand of type TControl.Cursor.

If you want to set the default directory in the wizard, just use the components for it, as in regular Delphi code.

For example, set the directory to a custom value:

WizardForm.DirEdit.Text := 'c:\test'; 

to read this value, you can use the WizardDirValue function.

I say "just access" ... but it took me an hour to figure out;)

+9
source

There seems to be no way to change the script constant using scripts.
I think your best bet is to change the destination directory for each entry in the [Files] section, for example.

 [Files] Source: "MYPROG.EXE"; DestDir: "{code:NewTargetDir}" 

and get the new installation directory as follows:

 [Code] function NewTargetDir(Param: String): String; begin Result := ExpandConstant('{app}') + '\MySubDir'; end; 

Since the NewTargetDir function is called immediately before copying the file, this should work.

However, I think you should reconsider your approach. First, ask the user to specify the directory to install, and then actually install to another directory, which seems to be your intention, is the wrong way, IMO. Do you really have a good reason to install in a different directory than the one specified by the user? Also, the result of my sample code could be achieved by specifying

 [Files] Source: "MYPROG.EXE"; DestDir: "{app}\MySubDir" 

without any scripts. If in doubt, see a simpler solution.

+3
source

I have the same situation where the setup application gets the installation path from the command line. I am using the solution suggested by Jonx:

 WizardForm.DirEdit.Text := 'c:\test'; 

Example:

 function CompareParameter(param, expected: String): Boolean; begin Result := False; if Length(param) >= Length(expected) then begin if CompareText(Copy(param, 1, Length(expected)), expected) = 0 then begin Result := True; end; end; end; function GetParameter(expectedParam: String): String; var i : LongInt; begin Result := ''; for i := 0 to ParamCount() do begin if CompareParameter(ParamStr(i), '/' + expectedParam + '=') then begin Result := Copy(ParamStr(i), Length(expectedParam) + 3, Length(ParamStr(i))); break; end; end; end; procedure InitializeWizard(); var newInstallFolder: String; begin newInstallFolder := GetParameter('INSTALL_FOLDER'); if Length(newInstallFolder) > 2 then begin if Copy(newInstallFolder, 1, 1) = '"' then newInstallFolder := Copy(newInstallFolder, 2, Length(newInstallFolder) - 2) if Length(newInstallFolder) > 1 then WizardForm.DirEdit.Text := newInstallFolder; end; end; 

The setup application starts from another installation in silent mode. This worked fine for me.

+2
source

All Articles