Pinning .jar files to the taskbar in windows 7

1.1k views Asked by At

My question is an extension on another question already answered, https://superuser.com/questions/257467/windows-7-how-to-pin-a-jar-to-the-taskbar

Is there a way to pin a jar to the taskbar, and have the window generated by the jar register as a different process, thus creating a different icon in the task bar? because as it stands, using any of the methods listed in the answer to the above question, you end up with a shortcut that can be pinned. but it is just a shortcut and only that, not the program itself. Im willing to try anything at this point as it is beginning to be very bothersome. not only does it look unprofessional, it uses up unnecessary screen real estate. As I know someone is going to ask what else I've tried, here's a bit of code i tried to run in c# to launch the jar, but of course, it does the same thing, registering the new process as a new process. (should have thought that one through.)

string strCmdText;
strCmdText = "-jar ImgurDownloader.jar";
Process process = new Process();
process.StartInfo.Arguments = strCmdText;
process.StartInfo.FileName = "javaw";
process.StartInfo.UseShellExecute = false;
process.Start();

so then I tried this:

string strCmdText;
strCmdText = "-jar ImgurDownloader.jar";
Process process = Process.GetCurrentProcess();
process.StartInfo.Arguments = strCmdText;
process.StartInfo.FileName = "javaw";
process.StartInfo.UseShellExecute = false;
process.Start();

and yet still, even if i try and replace the current process, it comes across as a new process, and thus a second icon in the taskbar. Please excuse my possibly short tone, the frustration is starting to kick in after a couple weeks.

Edit: have also tried setting the UAMID (User Application Model ID) using the JNA library to access shel32.dll's functions. The following is the code in the jar

public static void setCurrentProcessExplicitAppUserModelID(final String appID) {
    if (SetCurrentProcessExplicitAppUserModelID(new WString(appID)).longValue() != 0)
        throw new RuntimeException("unable to set current process explicit AppUserModelID to: " + appID);
}

public static String getCurrentProcessExplicitAppUserModelID() {
    final PointerByReference r = new PointerByReference();

    if (GetCurrentProcessExplicitAppUserModelID(r).longValue() == 0) {
        final Pointer p = r.getValue();

        return p.getString(0, true); // here we leak native memory by
                                        // lazyness
    }
    return "N/A";
}

private static native NativeLong GetCurrentProcessExplicitAppUserModelID(PointerByReference appID);

private static native NativeLong SetCurrentProcessExplicitAppUserModelID(WString appID);

static {
    Native.register("shell32");
}

then just call the set method. Tested with the get method, however,

NOTE: getCurrentProcessExplicitAppUserModelID is a lazy method and breaks things later on if used.

then in the C# Wrapper,

    [DllImport("shell32.dll")]
    public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);

    static void Main()
    {
        int der = SetCurrentProcessExplicitAppUserModelID("MAndWorks.ImgurDownloader.ImgurDownloader.2.0.0.0");
        string strCmdText;
        Console.WriteLine(der);
        strCmdText = "-jar ImgurDownloader.jar";
        Process process = new Process();
        process.StartInfo.Arguments = strCmdText;
        process.StartInfo.FileName = "javaw";
        process.StartInfo.UseShellExecute = false;
        process.Start();
        process.WaitForExit();
        Console.WriteLine("AWFURA");
    }
0

There are 0 answers