The WorkingDir parameter can be an empty string, in which case it will try to extract a pathname from the Filename parameter and use that as the initial current directory for the process. If no pathname was specified in Filename, a default directory will be used.
If you have a single string containing both a filename and parameters (e.g. a command line obtained from an UninstallString registry value), you need not separate them yourself; just pass '>' in the Filename parameter, and the full command line in the Params parameter. (Note that when this is done, the function's special platform-independent support for .bat and .cmd files is disabled; it simply passes the specified command line to CreateProcess without any processing.)
By default, when Setup/Uninstall is running in 64-bit install mode, this function disables WOW64 file system redirection when calling CreateProcess. It is possible to override this by calling EnableFsRedirection.
-
Can't be used to execute Setup itself.
+
Can't be used to execute Setup itself until the installation has started.
Note: compared to ISPP's Exec the ShowCmd and Wait parameters are swapped!
var
ResultCode: Integer;
@@ -1687,7 +1687,7 @@ end;
Note that passing a Wait value other than ewNoWait will have no effect if a new process isn't spawned (for example, if the file is opened inside an already-running instance of the program that handles the file type).
Attempts to change the name of the file or directory specified by OldFile to NewFile. If the operation succeeds, RenameFile returns True. If it cannot rename the file (for example, if a file called NewName already exists), it returns False.
-
Can't be used to rename Setup itself.
+
Can't be used to rename Setup itself until the installation has started.
Copies ExistingFile to NewFile, preserving time stamp and file attributes. If FailIfExists is True it will fail if NewFile already exists, otherwise it will overwrite it. Returns True if successful, False otherwise.
-
Can't be used to copy Setup itself.
+
Can't be used to copy Setup itself until the installation has started.
DeleteFile
diff --git a/Projects/Src/Setup.ScriptFunc.pas b/Projects/Src/Setup.ScriptFunc.pas
index aa1269798..f534cd1c0 100644
--- a/Projects/Src/Setup.ScriptFunc.pas
+++ b/Projects/Src/Setup.ScriptFunc.pas
@@ -112,10 +112,13 @@ procedure InitializeScaleBaseUnits;
ScaleBaseUnitsInitialized := True;
end;
-function IsSrcExe(const Filename: String): Boolean;
+function IsProtectedSrcExe(const Filename: String): Boolean;
begin
- var ExpandedFilename := PathExpand(Filename);
- Result := PathCompare(ExpandedFilename, SetupLdrOriginalFilename) = 0;
+ if (MainForm = nil) or (MainForm.CurStep < ssInstall) then begin
+ var ExpandedFilename := PathExpand(Filename);
+ Result := PathCompare(ExpandedFilename, SetupLdrOriginalFilename) = 0;
+ end else
+ Result := False;
end;
{---}
@@ -557,7 +560,7 @@ function CommonFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack
Stack.SetBool(PStart, True);
end else if (Proc.Name = 'COPYFILE') or (Proc.Name = 'FILECOPY') then begin
ExistingFilename := Stack.GetString(PStart-1);
- if not IsSrcExe(ExistingFilename) then
+ if not IsProtectedSrcExe(ExistingFilename) then
Stack.SetBool(PStart, CopyFileRedir(ScriptFuncDisableFsRedir,
ExistingFilename, Stack.GetString(PStart-2), Stack.GetBool(PStart-3)))
else
@@ -948,7 +951,7 @@ function InstFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack:
InternalError(Format('Must call "%s" function with Wait = ewWaitUntilTerminated', [Proc.Name]));
Filename := Stack.GetString(PStart-1);
- if not IsSrcExe(Filename) then begin
+ if not IsProtectedSrcExe(Filename) then begin
{ Disable windows so the user can't utilize our UI during the InstExec
call }
WindowDisabler := TWindowDisabler.Create;
@@ -976,7 +979,7 @@ function InstFuncProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack:
NoUninstallFuncError(Proc.Name);
Filename := Stack.GetString(PStart-2);
- if not IsSrcExe(Filename) then begin
+ if not IsProtectedSrcExe(Filename) then begin
{ Disable windows so the user can't utilize our UI during the
InstShellExec call }
WindowDisabler := TWindowDisabler.Create;
@@ -1410,7 +1413,7 @@ function SysUtilsProc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack:
Stack.SetString(PStart, NewFileSearch(ScriptFuncDisableFsRedir, Stack.GetString(PStart-1), Stack.GetString(PStart-2)));
end else if Proc.Name = 'RENAMEFILE' then begin
OldName := Stack.GetString(PStart-1);
- if not IsSrcExe(OldName) then
+ if not IsProtectedSrcExe(OldName) then
Stack.SetBool(PStart, MoveFileRedir(ScriptFuncDisableFsRedir, OldName, Stack.GetString(PStart-2)))
else
Stack.SetBool(PStart, False);