Launch4j, NSIS, and duplicate pinned Windows 7 taskbar icons
Asked Answered
B

2

5

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 "$SMPrograms\MyApp\MyApp.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.

Bria answered 25/3, 2011 at 22:8 Comment(2)
Is Launch4j or java.exe the owner of the window that has a taskbar button?Especial
@Especial I'll say it's javaw.exe, because that's the only process that shows up after running the original program .exe. Launch4j just generates a small .exe that wraps the .jar, and then I suppose executes javaw to actually run the original .jar file. That seems to imply that the problem I'm trying to solve is impossible, because I can't control the AppUserModelID of javaw.exe, right? That would kind of suck...Bria
E
2

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%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar) 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

Especial answered 26/3, 2011 at 0:4 Comment(5)
I took a look at the .lnk file and couldn't find any instances of the hex values you indicated. I'm not sure if it's an endianness problem, but I did a search for lots of the hex substrings, and couldn't find anything in the .lnk. I'll do some more research to see what's up, but maybe the problem is as simple as the plugin not properly setting the AppModelUserID inside the .lnk file.Bria
@Bria Are you using the unicode version of nsis? I used the normal ansi build in my test (And as you can see, it works for me)Especial
Yes, I am, sorry. I probably should have specified that -- my mistake. I'll try obtaining the ANSI build and see how that goes.Bria
Switching to the ANSI build of NSIS did the trick! Thanks so much for guiding me in that direction!Bria
Note: I checked the .lnk file again and was STILL unable to find an instance of the hex value pattern you mentioned above, but it's working now so I'm less concerned with that! Thanks again.Bria
J
1

This library claims that it can correctly pin Java application to the Windows 7 taskbar with the right icon and name...

http://www.strixcode.com/j7goodies/

See Microsoft explanation:

http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx

Solution in SO: Using JNA to get/set application identifier

Edited:

It seems that InnoSetup has provided support for Windows 7 Jump List since version 5.3.5 by using AppUserModelID parameter for an entry under [Icons] section...it is really a life-saver to this annoying issue...

The following code is still needed to tell Windows 7 that this application process shares the same AppUserModelID as the Windows-7 compatible shortcut created by InnoSetup

//name: must match AppUserModelID name set in an entry under [Icons] section
shell32.SetCurrentProcessExplicitAppUserModelID(name);

With this InnoSetup feature, it will automatically allow pinning and grouping when it detects the same AppUserModelID name.

see http://copyandpastecode.blogspot.com/2010/07/windows-7-jump-list-not-appearing-on.html

Jaguarundi answered 26/3, 2011 at 0:27 Comment(4)
Thanks for your suggestions @eee. I've already tried J7Goodies and the trial version just bails when I start up the app. It's also not free. The SO solution you've provided is the one that I linked to in my original post, so I've already got all that stuff working. Thanks for the idea though... not sure where to take it from here.Bria
@Bria In your launch4j script, did you set for <singleInstance> mode so that the application can only have one instance?...From your problem, it looks like it is creating more than one instance causing the launcher to show more than one application "icon" on the taskbar...Can you double-check your applications process in the TaskManager for multiple instances?Jaguarundi
Only one instance is running. The problem isn't that there are two separate windows grouped into the same folded icon -- the problem is that when I click the pinned taskbar link, the program appears as a new taskbar icon instead of appearing 'inside' the icon I clicked on. Please see the image here.Bria
@Bria It seems that InnoSetup has provided support for Windows 7 Jump List by using AppUserModelID parameter for an entry under [Icons] section...it is really a life-saver to this annoying issue... see copyandpastecode.blogspot.com/2010/07/…Jaguarundi

© 2022 - 2024 — McMap. All rights reserved.