NSIS CreateShortcut insists on using %ProgramFiles% for the icon path
Asked Answered
R

4

5

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?

Ricard answered 25/4, 2012 at 21:22 Comment(0)
U
9

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

Upward answered 14/8, 2012 at 16:25 Comment(0)
M
2

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)

Measures answered 25/4, 2012 at 22:47 Comment(0)
A
0
  1. Disable redirection
  2. Load Icon from path

All is done with System plugin. Why to complicate ...

Adowa answered 14/8, 2012 at 16:30 Comment(0)
B
0

http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.3.4 seems to be wrong, for me what worked was:

CreateShortCut "$SMPROGRAMS\${PRODUCT_PUBLISHER}\${SHORTCUT_NAME}.lnk" "$INSTDIR\${PRODUCT_EXE}" "$INSTDIR\${PRODUCT_EXE}" "$INSTDIR\MyIcon.ico"
Bombsight answered 2/10, 2012 at 23:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.