Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping separate processes in the Windows Taskbar

I have a number of separate processes that are logically related (but all are started separately - there is no common 'parent' process).

Is it possible to make them appear as one group in the Windows Taskbar?

Working sample

Here's some working code inspired by Remy's answer

using System;
using System.Runtime.InteropServices;
using System.Security;

namespace ConsoleApplication1
{
    [SuppressUnmanagedCodeSecurity]
    internal static class SafeNativeMethods
    {
        [DllImport("shell32.dll")]
        public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);

        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();

        [DllImport("kernel32.dll")]
        public static extern bool FreeConsole();
    }

    internal class Program
    {
        public static int SetApplicationUserModelId(string appId)
        {
            // check for Windows 7
            Version version = Environment.OSVersion.Version;
            if ((version.Major > 6) || (version.Major == 6 && version.Minor >= 1))
                return SafeNativeMethods.SetCurrentProcessExplicitAppUserModelID(appId);
            return -1;
        }

        [STAThread]
        public static void Main(string[] args)
        {
            int result = SetApplicationUserModelId("Gardiner.Sample1");

            SafeNativeMethods.AllocConsole();

            // Now we have a console, we can write to it
            Console.Title = "Sample 1";

            Console.WriteLine("Sample 1 {0}", result);
            Console.ReadLine();
            SafeNativeMethods.FreeConsole();
        }
    }
}

To get this to work, the executable must be set to have 'Output type' set to 'Windows Application', and configure the 'Startup object' to be 'ConsoleApplication1.Program' (for the code sample above).

like image 688
David Gardiner Avatar asked Dec 17 '12 23:12

David Gardiner


1 Answers

Yes, but only in Windows 7 and later. Multiple processes and windows are grouped together on the Taskbar if they have the same Application User Model ID assigned to them.

like image 188
Remy Lebeau Avatar answered Nov 15 '22 09:11

Remy Lebeau