Pinning to the taskbar a “chained process”

后端 未结 2 736
感情败类
感情败类 2020-12-06 15:58

Let\'s say I have two programs called launcher.exe and launchee.exe. The launcher display a button which -when clicked- starts launchee.exe<

2条回答
  •  抹茶落季
    2020-12-06 16:28

    I had the same problem and finally managed to find a nice solution for this. Setting the RelaunchCommand was not working for me any more with the newest Windows 10 Update.

    For simplicity i used "App" as name instead of "Launchee" as it could be confused with Launcher easily.

    Short Version:

    Launcher.exe and App.exe are grouped together in the taskbar. Laucher.exe does the update part and starts the App.exe as usual. If you choose 'Pin to taskbar' when the Launcher is running, it will pin the Launcher to the taskbar. If the App is already started and you pin this one to the taskbar, it will still pin the Launcher to the taskbar as they are grouped together.

    Long Version:

    That both Applications are grouped together in the taskbar, they share the same AppID. This could be done like described here: How to group different apps in Windows task bar?

    The starter should have an UI that an icon is shown in the taskbar. In my case it is a SplashScreen as UI. It starts the App.exe and the Laucher waits two seconds until the App.exe is started that they share for a small amount of time the same symbol in the taskbar. Then the Launcher could close and if you pin the App afterwards it will pin the Launcher to the taskbar.

    Here you could find an example Application which is started, it's a WPF App:

    using System.Runtime.InteropServices;
    using System.Windows;
    
    namespace TestApp
    {
        public partial class MainWindow : Window
        {
            [DllImport("shell32.dll", SetLastError = true)]
            private static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
    
            private const string AppID = "73660a02-a7ec-4f9a-ba25-c55ddbf60225"; // generate your own with: Guid.NewGuid();
    
            public MainWindow()
            {
                SetCurrentProcessExplicitAppUserModelID(AppID);
                InitializeComponent();
                Topmost = true; // to make sure UI is in front once
                Topmost = false;
            }
        }
    }
    

    Second WPF App which is the Launcher/Starter:

    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Threading.Tasks;
    using System.Windows;
    
    namespace TestStarter
    {
        public partial class MainWindow : Window
        {
            [DllImport("shell32.dll", SetLastError = true)]
            private static extern void SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
    
            private const string AppID = "73660a02-a7ec-4f9a-ba25-c55ddbf60225"; // generate your own with: Guid.NewGuid();
    
            public MainWindow()
            {
                SetCurrentProcessExplicitAppUserModelID(AppID);
                InitializeComponent();
                Process.Start(@"C:\Test\TestApp.exe");
                ExitAfterDelay();
            }
    
            private async void ExitAfterDelay()
            {
                await Task.Delay(2000);
                Environment.Exit(0);
            }
        }
    }
    

提交回复
热议问题