.net – 在Windows任务栏中对单独的进程进行分组

我有许多逻辑相关的独立进程(但所有进程都是单独启动的 – 没有共同的’父’进程).

是否可以使它们在Windows任务栏中显示一个组?

工作样本

这是一些灵感来自雷米答案的工作代码

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();
        }
    }
}

要使其工作,必须将可执行文件设置为将“输出类型”设置为“Windows应用程序”,并将“启动对象”配置为“ConsoleApplication1.Program”(对于上面的代码示例).

解决方法

是的,但仅限于Windows 7及更高版本.如果多个进程和窗口具有分配给它们的相同 Application User Model ID,则它们在任务栏上组合在一起.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...