Inno Setup FileExists Cannot Find Existing File

In my script, I check if a directory and two files exist in this directory. While the first returns the correct value, the second check fails. I checked it several times that these files exist in the specified directory, but Inno Setup will always tell me that they do not exist. This happens on a Windows virtual server and cannot be played on my local machine. There it always returns the correct value.

UpdatePath := ExpandConstant('{app}'); if DirExists(UpdatePath) then begin ExePath := UpdatePath+'\Application.exe'; ConfigFilePath := UpdatePath+'\Application.exe.config'; if FileExists(ExePath) and FileExists(ConfigFilePath) then begin //this one returns incorrect values //Do Stuff end else begin MsgBox(FmtMessage(CustomMessage('DirPageFileNotFound'), [ExePath, ConfigFilePath]),mbInformation,MB_OK); Result := False; end; end else begin MsgBox(FmtMessage(CustomMessage('DirPageDirectoryNotFound'), [UpdatePath]),mbInformation,MB_OK); Result := False; end; 

As you can see, I am checking the executable file, which can also be executed with a double click. It is there, but Inno Setup will always tell me that it is not. Is the virtual environment associated with it? What's going on here?

+2
inno-setup pascalscript
Nov 20 '15 at 7:23
source share
1 answer

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); 
0
Nov 20 '15 at 8:15
source share



All Articles