简体   繁体   English

NSIS CreateShortcut坚持使用%ProgramFiles%作为图标路径

[英]NSIS CreateShortcut insists on using %ProgramFiles% for the icon path

I have the following NSIS code 我有以下NSIS代码

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 安装日志显示以下内容(来自detailprint命令)图标路径: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." 如果我打开lnk文件或右键单击快捷方式并单击“更改图标...”,我收到错误“Windows无法找到文件%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. 如果我浏览到%ProgramFiles%,它会转到c:\\ Program Files,而不是详细说明命令中显示的x86版本。 The icon file exists, but in the x86 folder. 图标文件存在,但在x86文件夹中。

It appears that either NSIS or windows is replacing "C:\\Program Files (x86)\\" with "%ProgramFiles%", which doesn't point to the x86 version. 似乎NSIS或Windows正在用“%ProgramFiles%”替换“C:\\ Program Files(x86)\\”,它不指向x86版本。

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... 我真的不明白为什么这对64位系统有帮助,但它确实......

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 在APPLICATION_ICON之前添加第二个\\后,将再次显示图标

Confusing but it works 令人困惑,但它有效

NSIS just uses the documented IShellLink interface. NSIS只使用记录的IShellLink接口。 There is a thread about it on the NSIS forum (with a workaround you can try). 有一个线程关于它的NSIS论坛(一个变通方法,您可以试试)。 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) 我相信它是WOW64中的一个错误...(注册表重定向器被注释为将%ProgramFiles%更改为%ProgramFiles(x86)%,我怀疑IShellLink缺少此hack)

  1. Disable redirection 禁用重定向
  2. Load Icon from path 从路径加载图标

All is done with System plugin. 一切都是使用System插件完成的。 Why to complicate ... 为什么复杂化......

http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.3.4似乎是错的,对我来说有用的是:

CreateShortCut "$SMPROGRAMS\${PRODUCT_PUBLISHER}\${SHORTCUT_NAME}.lnk" "$INSTDIR\${PRODUCT_EXE}" "$INSTDIR\${PRODUCT_EXE}" "$INSTDIR\MyIcon.ico"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM