Stander
11th November 2010 10:37 UTC
IfFileExists and quotes
Hi!
Recently I was trying to read the "UninstallString" from the system registry and check if the uninstaller file exists.
ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\My_App" \
"UninstallString"
IfFileExists $R0 +1 done
The problem is that if the file path stored in the registry includes quotes, the
IfFileExists function always returns
false.
Example
if $R0 = C:\Program files\MyApp\uninstall.exe then
IfFileExists returns true (file exists)
but
if $R0 = "C:\Program files\MyApp\uninstall.exe" then
IfFileExists returns false (file doesn't exist)
Is there any way to make it work or to exclude quotes from the received value (path)?
Regards,
Stander
MSG
11th November 2010 11:27 UTC
To remove a " from the beginning of the string:
StrCpy $R1 $R0 1
${If} $R1 == '"'
StrCpy $R0 $R0 "" 1
${EndIf}
I'll leave the removal of a trailing " character as an exercise to you.
(Hint: http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.8 )
Stander
11th November 2010 17:16 UTC
Thanks a lot MSG!
Homework done! :)
StrCpy $R1 $R0 "" -1
${If} $R1 == '"'
StrCpy $R0 $R0 -1
${EndIf}
But... I'm wondering why the
IfFileExists function doesn't respect quotes.
Many other functions have no problems with paths with quotes.
For instance
ExecWait accepts all paths, no matter if they include quotes or not.
Moreover, according to
this guide it is even recommended to use quotes in paths saved to the registry.
Anders
11th November 2010 18:51 UTC
Any instruction that executes a new process should be quoted, for everything else, quotes are probably not required. IfFileExists probably ends up calling the win32 api GetFileAttributes, and it does not want quoted paths (Like most win32 functions)
Stander
11th November 2010 22:06 UTC
Originally posted by Anders
Any instruction that executes a new process should be quoted, for everything else, quotes are probably not required. IfFileExists probably ends up calling the win32 api GetFileAttributes, and it does not want quoted paths (Like most win32 functions)
Thanks for the explanation.
Regards,
Stander