Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

java - Launch4j, NSIS, and duplicate pinned Windows 7 taskbar icons

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.

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.

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.

... 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.

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}"

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.

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...

Thanks!

EDIT: 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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)


WinShell+lnk dump


HEX LNK


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...