To fix the problem, try adding the following code. Then check the installer log file and the output of the dir command:
#ifdef UNICODE #define AW "W" #else #define AW "A" #endif function GetFileAttributes(lpFileName: string): DWORD; external 'GetFileAttributes{#AW}@kernel32.dll stdcall'; function GetLastError() : LongInt; external 'GetLastError@kernel32.dll stdcall'; const INVALID_FILE_ATTRIBUTES = $FFFFFFFF; procedure ...; var UpdatePath: string; ExePath: string; FindRec: TFindRec; Attrs: DWORD; LastError: LongInt; ResultCode: Integer; begin Log('InitializeWizard'); UpdatePath := ExpandConstant('{app}'); ExePath := UpdatePath+'\Application.exe'; if FileExists(ExePath) then begin Log(ExePath + ' exists'); end else begin LastError := GetLastError; Log(ExePath + ' does not exist - ' + Format('System Error. Code: %d. %s', [LastError, SysErrorMessage(LastError)])); end; if not FindFirst(UpdatePath + '\*', FindRec) then begin LastError := GetLastError; Log(UpdatePath + ' not found - ' + Format('System Error. Code: %d. %s', [LastError, SysErrorMessage(LastError)])); end else begin repeat Log('Found file: ' + FindRec.Name + ' in ' + UpdatePath); until not FindNext(FindRec); end; Attrs := GetFileAttributes(ExePath); if Attrs <> INVALID_FILE_ATTRIBUTES then begin Log(ExePath + ' attributes = ' + IntToStr(Attrs)); end else begin LastError := GetLastError; Log(Format('Cannot get attributes of ' + ExePath + ': System Error. Code: %d. %s', [ LastError, SysErrorMessage(LastError)])); end; Exec(ExpandConstant('{cmd}'), '/k dir "' + UpdatePath + '"', '', SW_SHOW, ewWaitUntilTerminated, ResultCode); end;
FileExists internally uses FindFirst / FindNext and GetFileAttributes . So it's figuring out what causes the problem.
I prefer to assume that the target computer is 64-bit, and for some reason the file system is being redirected.
Try using EnableFsRedirection to disable redirection before calling FileExists :
EnableFsRedirection(False);
Martin Prikryl Nov 20 '15 at 8:15 2015-11-20 08:15
source share