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?
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With