I used the code from this Answer from the Member TLama. I think it's exactly what i need, but I have two problems with it:
I need the Serial from the edit boxes in the registry. This is what i tried:
Root: "HKCU"; Subkey: "Software\myProg"; ValueType: string; ValueName: "Serial"; ValueData: "{code:GetSerialNumber}"; Flags: deletevalue uninsdeletevalue
but Inno gives me an error. TLama wrote in his answer (from the Link above), it's enought to call the GetSerialNumber part, but I do sth. wrong...
The other question: Is it possible to prefill the serialbox with an example code? E.g. 12345 or abcde? I'm using only one input box with 10 chars...
Hope someone can help, and sorry for my bad english ;)
You can use UserInfoPage and then {userinfoserial} but if you want to use TLama's solution then you should slightly change NextButtonClick function:
function NextButtonClick(CurPageID: Integer): Boolean;
var
S: string;
I: Integer;
begin
Result := True;
if CurPageID = SerialPage.ID then
begin
S := '';
for I := 0 to High(SerialEdits) do
S := S + SerialEdits[I].Text + '-';
SetLength(S, Length(S)-1);
RegWriteStringValue(HKEY_CURRENT_USER, 'Software\myProg',
'Serial', S);
end;
end;
Var SerialEdits: array of TEdit; has to be set as Global for the script. You also may want to add key to registry later (e.g. with CurStepChanged when ssDone or something) or write your own function that will pass Serial to Result as String and then call it in Registry Section.
Related
My scenario is currently that I'd like the possibility for users to skip installation of certain files that a user might have specified via a command line argument at install time.
The idea would be for the user to specify a text file and ideally during installation, the installer would check if the file currently being copied is listed in the supplied text file and decide depending on that.
My [Files] section atm is referencing full directories: would the best approach be to list all files individually and make use of the Check parameter or is there a different approach available? There seems to be no event function that would lend itself for this task.
Thanks
Markus
No need to list all files individually. The Check function is called for each file individually, even when the Source is a wildcard.
Use the CurrentFilename function to tell what file is being processed at the moment.
Note that the Check function is called multiple times for each file.
[Files]
Source: "C:\path\*.*"; DestDir: "{app}"; Check: AllowFile
[Code]
var
Whitelist: TStringList;
function AllowFile: boolean;
var
FileName: string;
begin
FileName := ExtractFileName(ExpandConstant(CurrentFileName));
Result := (Whitelist = nil) or (Whitelist.IndexOf(Uppercase(FileName)) >= 0);
if Result then
Log(Format('Allowing "%s"', [FileName]))
else
Log(Format('Skipping "%s"', [FileName]));
end;
function InitializeSetup(): Boolean;
var
WhitelistFile: string;
Lines: TArrayOfString;
I: Integer;
begin
WhitelistFile := ExpandConstant('{param:Whitelist}');
if WhitelistFile = '' then
begin
Log('No whitelist specified, allowing all files');
end
else
begin
Whitelist := TStringList.Create;
Whitelist.Sorted := True;
LoadStringsFromFile(WhitelistFile, Lines);
for I := 0 to GetArrayLength(Lines) - 1 do
Whitelist.Add(Uppercase(Lines[I]));
Log(Format('Loaded %d entries to whitelist from "%s"', [
Whitelist.Count, WhitelistFile]));
end;
Result := True;
end;
This question already has an answer here:
"Identifier Expected" or "Invalid Prototype" when implementing a scripted constant in Inno Setup
(1 answer)
Closed 1 year ago.
I'm using Inno Setup for my installation and am adding the following function to the existing [Code] section:
function Get64Or32: String;
begin
if IsWin64 then
begin
Result := 'Program Files (x86)';
end
else
begin
Result := 'Program Files';
end;
end;
I keep getting the following error:
10:41:08 Invalid prototype for 'Get64Or32'
I have tried several permutations including having the parenthesis after the function name but get the same error each time.
I'm attempting to use this from the [Registry] section to pinpoint the Java location:
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"JRE_HOME"; ValueData:"C:\{code:Get64or32}\Java\jre_1.8.0_151"; Flags: preservestringtype uninsdeletevalue uninsdeletekeyifempty; Permissions: users-modify;
If you look here Pascal Scripting: Scripted Constants it explains it all. To quote:
The syntax of a {code:...} constant is: {code:FunctionName|Param}
The Pascal script can contain several functions which are called when
Setup wants to know the value of a scripted {code:...} constant. The
called function must have 1 String parameter named Param, and must
return a String or a Boolean value depending on where the constant is
used.
The syntax of a {code:...} constant is: {code:FunctionName|Param}
It also provides:
An example function:
[Code]
function MyConst(Param: String): String;
begin
Result := ExpandConstant('{autopf}');
end;
An example useage:
[INI]
FileName: "{app}\MyIni.ini"; Section: "MySettings"; Key: "ShortApp"; String: "{code:GetShortName|{app}}"
You don't have to use the parameter but it must be part of the prototype.
I need that my program be protected with a dynamic password that includes the current date.
I need just the month or the day or the hour or the minute.
I tried this code to include the day into the password:
[Setup]
Password=Password!{code:DateTime|0}
[Code]
function DateTime (Param: string): string;
begin
Result := GetDateTimeString('dd', #0, #0);
end;
But it's not working.
Regards.
The Password directive cannot contain any constants, let alone scripted constants.
So your script makes the password be literally Password!{code:DateTime|0}.
Instead, use CheckPassword event function:
[Code]
function CheckPassword(Password: String): Boolean;
begin
Result := (Password = ('Password!' + GetDateTimeString('dd', #0, #0)));
end;
Though safer than comparing against a literal string (which can be seen in .exe binary) is comparing a checksum.
See How to do a dynamic password in Inno Setup?
I need a help with condition in [Run]. If it's possible...
I need to run a command that depends on a condition.
Like this:
if (UserPage.Values[0] = 'NC') then FileName: {sys}\inetsrv\appcmd.exe; Parameters: "set......"
Or other way to do it.
Regards.
You are looking for the Check parameter:
[Run]
FileName: "{sys}\inetsrv\appcmd.exe"; Parameters: "set......"; Check: ShouldRun
[Code]
function ShouldRun: Boolean;
begin
Result := (UserPage.Values[0] = 'NC');
end;
I want to change defaultdirname parameter in ssInstall part. How can I do that? Is there a function for setting [Setup] parameters.
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 access to it's componants like you would in normal delphi code.
For example, set the directory to a custom value:
WizardForm.DirEdit.Text := 'c:\test';
to read that value you can use the WizardDirValue function.
I say 'just access'... but it took me an hour to figure out ;)
There seems to be no way to change a script constant via scripting.
I think your best bet is to modify the target directory for each entry in the [Files] section, e.g.
[Files]
Source: "MYPROG.EXE"; DestDir: "{code:NewTargetDir}"
and derive your new installation directory like this:
[Code]
function NewTargetDir(Param: String): String;
begin
Result := ExpandConstant('{app}') + '\MySubDir';
end;
Since the NewTargetDir function will be called just before the file is actually copied, this should work.
However, I think you should reconsider your approach. First asking the user to specify a directory to installinto, and then actually installing into a different directory, which seems to be your intent, is the wrong way, IMO. Do you really have a compelling reason to install into another directory than the one specified by the user? Besides, the result of my example code could just as well be achieved by specifying
[Files]
Source: "MYPROG.EXE"; DestDir: "{app}\MySubDir"
without any scripting needed. When in doubt, go for the simpler solution.
I have a similar situation, where the setup app is receiving the install path from the command line.
I'm using the solution proposed 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 app is being started from another setup, in silent mode. It worked OK for me.