Launch4j、NSIS 和重复固定的 Windows 7 任务栏图标

Launch4j, NSIS, and duplicate pinned Windows 7 taskbar icons(Launch4j、NSIS 和重复固定的 Windows 7 任务栏图标)

本文介绍了Launch4j、NSIS 和重复固定的 Windows 7 任务栏图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,当我在 Windows 7 中为我的应用程序固定一个任务栏图标时,单击该图标会为该程序打开一个单独的(重复)图标,而不是将其与用于调用它的快捷方式分组.

I'm having a problem wherein when I pin a taskbar icon in Windows 7 for my application, clicking the icon opens up a separate (duplicate) icon for the program instead of keeping it grouped with the shortcut used to call it.

应用程序本身是一个 .jar 文件,它使用 Launch4j 打包成一个 .exe.这可以解释为什么图标会重复——Launch4j 正在调用 javaw.exe 的单独进程,当您开始执行此类操作时,看起来 AppModelUserID 会感到困惑.

The application itself is a .jar file that's been wrapped into an .exe using Launch4j. That would explain why the icon is getting duplicated -- Launch4j is calling a separate process of javaw.exe, and it looks like the AppModelUserID gets confused when you start doing stuff like that.

根据这篇文章,解决方案是指定您的AppModelUserID 通过一些本机代码.根据那里给出的示例,我成功地在我的应用程序中调用了 JNA 代码,看来我正在将其正确设置为MyCompany.MyApp"形式的值.调用get"函数会返回我为其设置的值,因此在应用程序端一切正常.

According to this post, the solution is to specify your AppModelUserID through some native code. I successfully got the JNA code being called within my application as per the example given there, and it would appear that I'm setting it properly to a value of the form "MyCompany.MyApp". Calling the 'get' function returns the value that I set for it, so everything appears to be OK on the application side.

...但这就是解决方案停止的地方!我不认为这是它的结束,因为它肯定不能解决我的问题!似乎 also 需要的是一个已创建的具有 same AppModelUserID 的快捷方式——这是我对 MSDN 文档的解释.

... but that's where that solution stops! I don't think it's the end of it because it sure doesn't fix the problem for me! It would appear that what's also required is a shortcut that's been created that has the same AppModelUserID -- this is my interpretation of the MSDN documentation.

由于我使用 NSIS 作为安装程序,因此我使用了 WinShell 插件在安装时设置应用程序快捷方式的属性.具体来说,该调用反映了以下示例:

Since I'm using NSIS as my installer, I used the WinShell plugin to set the properties of the application shortcut upon install. Specifically, the call mirrors the example of:

WinShell::SetLnkAUMI "$SMProgramsMyAppMyApp.lnk" "${MyApp_AppUserModelId}"

那是我拖到任务栏的那个……但同样,没有骰子.该应用程序仍以单独的固定图标打开.此时,我无法检查我是否正确设置了快捷方式属性,因为似乎没有工具可以检查给定快捷方式的 AppModelUserID 是什么.

That's the one I drag to the taskbar... but again, no dice. The application still opens in a separate pinned icon. At this point, I'm unable to check whether I've set the shortcut properties properly, because there doesn't seem to be a tool to check what the AppModelUserID is of a given shortcut.

当我直接创建一个指向 .jar 文件的快捷方式时,一切正常,但是尝试将 JRE 安装到 NSIS 会很麻烦,而且我已经经历过并试图避免的大量其他问题.

Everything works fine when I just create a shortcut directly to the .jar file, but then there's the hassle of trying to implement the JRE install into NSIS and a ton of other headaches I've already been through and am trying to avoid.

如果有任何指导可以帮助我解决这个烦人的问题,我将不胜感激!我总是被这些愚蠢的小美学问题所困扰,解决起来很痛苦......

I'd really appreciate any guidance that could help me to solve this nagging issue! I'm always plagued by these stupid little aesthetic issues that can be such a pain to solve...

谢谢!

按照 Anders 的建议,切换到 NSISANSI 版本解决了问题在我无法验证快捷方式的 AppModelUserID 实际上设置正确之后.

The problem was solved by switching to an ANSI build of NSIS, as recommended by Anders after I was unable to verify that the shortcut's AppModelUserID was in fact being set properly.

推荐答案

在十六进制编辑器中打开.lnk,AppModelUserId应该存储为unicode字符串,在28 4C 9F 79 9F 39 4B A8 D0 E1 D4之后大约15个字节2D E1 D5 F3

Open the .lnk in a hex editor, the AppModelUserId should be stored as a unicode string about 15 bytes after 28 4C 9F 79 9F 39 4B A8 D0 E1 D4 2D E1 D5 F3

除非我的(内部)LNK 转储程序错误,否则 WinShell::SetLnkAUMI 可以正常工作,问题可能不在于快捷方式,但可以肯定的是,您应该正常启动应用程序并将其固定到任务栏,然后进行比较固定的 .lnk (%APPDATA%MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar) 与 NSIS 在十六进制编辑器中创建的快捷方式(它们可能不是 100% 相等,但您应该能够在两者中将您的 AppModelUserId 视为 UTF16LE 字符串)

Unless my (internal) LNK dumper is wrong, WinShell::SetLnkAUMI works correctly and the problem is probably not with the shortcut, but just to be sure, you should start your app normally and pin it to the taskbar and then compare the pinned .lnk (%APPDATA%MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar) with the shortcut created by NSIS in a hex editor (They might not be 100% equal but you should be able to see your AppModelUserId as a UTF16LE string in both)

这篇关于Launch4j、NSIS 和重复固定的 Windows 7 任务栏图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Launch4j、NSIS 和重复固定的 Windows 7 任务栏图标

基础教程推荐