Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSIS CreateShortcut insists on using %ProgramFiles% for the icon path

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?

like image 691
John Avatar asked Apr 25 '12 21:04

John


Video Answer


2 Answers

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

like image 57
aeb78 Avatar answered Oct 28 '22 22:10

aeb78


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)

like image 41
Anders Avatar answered Oct 29 '22 00:10

Anders