9

I'm currently trying to pin a Java application to the Windows 7 taskbar. The application is launched with Launch4j. The program icon is displayed correctly but right-clicking the icon on the taskbar only shows a context-menu with the entry "Close window". No menu entry for pinning the application to the taskbar. Dragging the EXE file into the taskbar is also not working properly. When clicking this new launcher in the taskbar then a second icon spawns in the taskbar.

I followed the instructions of the solutions to these two questions to solve the problem but it didn't help:

The JNA stuff from the second question/solution compiles and doesn't throw any exception. I can read the app id after setting it. But I still can't pin the application to the taskbar.

I have created a small test application on Github which demonstrates the problem:

https://github.com/kayahr/launch4jtest

The application uses Maven as build system. Simply run mvn package and you'll find a ZIP file in the target directory which contains the EXE file and the jna.jar which is needed to set this app id. Extract this ZIP to some directory, double-click the EXE and try to pin the application to the taskbar and you'll see the problem.

So what's wrong with this application?

Community
  • 1
  • 1
kayahr
  • 18,296
  • 27
  • 93
  • 139
  • I've successfully done this but not through Maven for an executable created using Launch4J. You need to create an icon shortcut that embeds AppUserModelID information. InnoSetup can create such icon shortcut under [Icons] section. Supply the application name assigned to AppUserModelID via JNA. – ecle Feb 20 '12 at 12:51
  • See http://stackoverflow.com/questions/5646813/how-to-make-exe-file-for-izpack-installer-jar-file and http://stackoverflow.com/questions/5438651/launch4j-nsis-and-duplicate-pinned-windows-7-taskbar-icons – ecle Feb 20 '12 at 13:00
  • @eee Problem is: I need to create this installer on Linux because I have no access to a Windows box during build time. There is a plugin for NSIS but this also only runs on Windows because it directly calls some Windows API call. And even if I manage to modify these shortcuts: What happens when the user starts the EXE directly or creates a custom shortcut from the EXE file? Then it still doesn't work. – kayahr Feb 21 '12 at 09:28
  • On contrary, it still works in any order: (1) it works when dragging and dropping the EXE file (not its icon shortcut) into Windows 7 taskbar to create a pinned icon; (2) it works when running the EXE file and later choosing "pin to taskbar" option menu to create a pinned icon. If you don't set AppUserModelID, this is not possible; even it will cause a weird behavior like having javaw.exe "icon" on the taskbar instead of your exe icon since Launch4J calls the executable jar using javaw.exe – ecle Feb 21 '12 at 13:03
  • To run a Windows-based application on Linux OS, you can use wine http://katastrophos.net/andre/blog/2009/03/16/setting-up-the-inno-setup-compiler-on-debian/ – ecle Feb 21 '12 at 13:05
  • @eee But when it works when dragging the EXE to the taskbar then for what do I need this specially created shortcut at all? Don't understand this. Is InnoSetup doing more with this appUserModelId like registering it somewhere in the registry so Windows knows about it even when the application was not started with a shortcut which includes this id? – kayahr Feb 21 '12 at 15:44
  • @eee Oh, I'm silly. I just installed this NSIS plugin in the wrong way. It is no problem running it on Linux. It indeed works when such a special shortcut is installed by the installer. But I still don't understand WHY this shortcut is needed because the EXE now works without ever touching this shortcut. – kayahr Feb 21 '12 at 16:24
  • maybe, internally InnoSetup does something magical when it found AppUserModelID parameter in a icon shortcut entry... :) – ecle Feb 22 '12 at 12:10
  • @eee I think the magic is done in Windows. As long as at least one shortcut exists, taskbar-pinning works correctly. When I delete the last shortcut pointing on the EXE file then taskbar-pinning no longer works. Well, for me this quesion is solved. If you like you may add an answer with your "You have to create a shortcut with embedded appUserModelId" solution so I can accept it? – kayahr Feb 22 '12 at 13:07

2 Answers2

5

N.B. Rewritten some comments originally in the main post as per kayahr's request :)

You need to create an icon shortcut that embeds AppUserModelID information. InnoSetup can create such icon shortcut under [Icons] section. Supply the application name assigned to AppUserModelID via JNA. Suggested links to read:

How to make .exe file for izpack installer .jar file

Launch4j, NSIS, and duplicate pinned Windows 7 taskbar icons

  1. It works when dragging and dropping the EXE file (not its icon shortcut) into Windows 7 taskbar to create a pinned icon;
  2. It works when running the EXE file and later choosing "pin to taskbar" option menu to create a pinned icon. If you don't set AppUserModelID, this is not possible; even it will cause a weird behavior like having javaw.exe "icon" on the taskbar instead of your exe icon since Launch4J calls the executable jar using javaw.exe (duplicated pinned icons)

To run Windows-based installer builder under Linux, refer this as a guide:

http://katastrophos.net/andre/blog/2009/03/16/setting-up-the-inno-setup-compiler-on-debian/

Yes, as mentioned by kayahr, this Windows 7 feature will only work when its icon shortcut with embedded AppUserModelID remains intact (i.e. it is not removed/deleted).

Community
  • 1
  • 1
ecle
  • 3,761
  • 1
  • 15
  • 20
  • It should be noted that this method only works if the shortcut is available in a specific location! The Start Menu. I can confirm that this does not work if you have the installer create the shortcut in Program Files (next the the `.exe`). I was loosing my mind trying to figure out why I was unable to pin when starting from the exe (I could only pin by dragging the shortcut to task bar, after pinning starting from exe did not group with the pinned shortcut). It is worth mentioning that I'm running a non-administrator user account and this may be permissions related. – predi Nov 19 '15 at 09:05
0

I use InnoSetup to create installer for my java application. To make my app's icon pinable I do two steps:

  1. Set AppUserModelID for my app:
  • Add package from Maven: net.java.dev.jna/jna-platform-5.7.0

  • set AppUserModelID

    WString id = new WString("TMP.TestApp");
    Shell32.INSTANCE.SetCurrentProcessExplicitAppUserModelID(id);

  1. Use AppUserModelID when creating icon with InnoSetup

    [Icons]

    Name: "{commondesktop}\TestApp"; Filename: "{app}\run.bat"; WorkingDir: "{app}";IconFilename:"{app}\test-icon.ico"; AppUserModelID: "TMP.TestApp"; Flags: runminimized