I have the following NSIS code
Function CreateDesktopSC
;Creates Desktop Shortcut
SetShellVarContext current
SetOutPath "$DOCUMENTS\Foo\"
SetShellVarContext all
detailprint "Icon path: $INSTDIR\Bar\icon.ico"
CreateShortCut "$DESKTOP\${productName}.lnk" "$INSTDIR\Bar\binary.exe" "" "$INSTDIR\Bar\icon.ico" 0
FunctionEnd
The install log shows the following (from the detailprint command) Icon path: C:\Program Files (x86)\Bar\icon.ico
The shortcut is created, but with the icon from the executable.
If I open the lnk file or right click the shortcut and click "Change Icon ...", I get the error "Windows can't find the file %ProgramFiles%\Bar\icon.ico."
If I browse to %ProgramFiles%, it takes me to c:\Program Files, not the x86 version as shown in the detailsprint command. The icon file exists, but in the x86 folder.
It appears that either NSIS or windows is replacing "C:\Program Files (x86)\" with "%ProgramFiles%", which doesn't point to the x86 version.
The actual path to the executable is correct, it's only the icon link which is incorrect.
Any ideas?
The workaround from the thread is to add an second \ to your icon code. I didn't really got why this helps on 64bit systems but it does...
so replace:
CreateShortCut "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_NAME}.lnk" "yourapp.exe" "$INSTDIR\${APPLICATION_ICON}"
with
CreateShortCut "$SMPROGRAMS\$StartMenuGroup\${PRODUCT_NAME}.lnk" "yourapp.exe" "$INSTDIR\\${APPLICATION_ICON}"
After adding the second \ before APPLICATION_ICON the icon will be displayed again
Confusing but it works
NSIS just uses the documented IShellLink interface. There is a thread about it on the NSIS forum (with a workaround you can try). I believe it is a bug in WOW64... (The registry redirector is docmented to change %ProgramFiles% to %ProgramFiles(x86)% behind your back, I suspect IShellLink is missing this hack)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With