Archive: Problem With IfFileExists on 64bit Windows


Problem With IfFileExists on 64bit Windows
I recently wrote script were I have to check existence of certain driver in users system. I did it by checking if driver file was in Windows\System32\drivers folder with IfFileExists command. I noticed that in 32bit Windows this method worked, but in 64bit Windows IfFileExist does not seems to see *.sys files in Windows\System32\drivers. If I use IfFileExist on some other files in other path it seems to work as it should in 64bit Windows.

I wrote this little script to demonstrate problem. It looks beep.sys that should (hopefully) exist on every Windows machine.


Name "beepexist"
OutFile "beepexist.exe"

SetDateSave on
SetDatablockOptimize on
CRCCheck on
SilentInstall normal
XPStyle on

Function .onInit

IfFileExists $SYSDIR\drivers\beep.sys 0 notfound

MessageBox MB_OK "beep.sys found at: $SYSDIR\drivers\"
Goto end

notfound:

MessageBox MB_OK "No beep.sys found at: $SYSDIR\drivers\"

end:

FunctionEnd

Section "-boo"
;
SectionEnd


I first thought that $SYSDIR could give wrong path to C:\Windows\SysWOW64\drivers but path seems to correct and hardcoding path in script give same results. Why IfFileExists shows such behaviour on 64bit Windows ? Or have I understood something wrong?

Best regards

Disable file system redirection with the macros in x64.nsh, then $sysdir will be correct. Or use the half documented $windir\sysnative hack on 64 bit OS


Thank you for your answer. I did not understood that redirection happens even when I hardcode path to like this:


IfFileExists C:\Windows\System32\drivers\beep.sys 0 notfound


Instead of using $SYSDIR.

Redirection is done by the OS not NSIS.

Stu