Search code examples
uwpdesktop-bridge

How to minimize desktop bridge app after login?


I already know how to set up the application to start when I log in, This is my code:

<uap5:Extension
    Category="windows.startupTask"
    Executable="DC.AutoRun\AutoRun.exe"
    EntryPoint="Windows.FullTrustApplication">
  <uap5:StartupTask
    TaskId="AutoRunTest"
    Enabled="true"
    DisplayName="AutoRun Test" />
</uap5:Extension>

but I need to minimize it. 'IActivatedEventArgs' seems not applicable to Win32:

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.StartupTask)
    {
        //Some code
    }
}

Then I found this link, which talks about using an additional app to start the target app with the specified parameters, and then the target app is minimized according to parameters, sounds like it can work, but how to start target app in one app?

Thank you for reading and have a good day!


Solution

  • I'm afraid you could not specify a parameter for startup task as Stenfan said. And he has provided a possible work around that is to launch a different EXE that then launches your app.

    The general steps are register app protocol for your desktop-bridge app.

    for example:

    <Extensions>
      <uap:Extension Category="windows.protocol">
        <uap:Protocol Name="startup" />
      </uap:Extension>
    </Extensions>
    

    Then make a startup win32 application to launch your desktop-bridge app with parameter (startup:minimize). You could get the parameter in the following method.

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
    }
    

    Process parameter.

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();
        if (e.Args.Length > 0)
        {
            var para = e.Args.First();
            var strList = para.Split(':');
            var res = strList.Last();
            if (res == "minimize")
            {      
                mainWindow.WindowState = WindowState.Minimized;                              
            }
        }
    }