简体   繁体   中英

Unable to launch UWP app with ProcessStartInfo

I had to deploy UWP app says examples “OfflineFacialLogin”, I am able to launch “OfflineFacialLogin” manually from the command prompt like this

“C:\Windows\System32>OfflineFacialLogin”

and same code works debug environment with below code.

var proc = new ProcessStartInfo();
string yourCommand;
yourCommand = OfflineFacialLogin.exe”;
proc.UseShellExecute = true;
proc.WorkingDirectory = @”C:\Windows\System32″;
proc.FileName = @”C:\Windows\System32\cmd.exe”;
proc.Arguments = “/c ” + yourCommand;
proc.WindowStyle = ProcessWindowStyle.Normal;process.Start(proc);

But after placing this code dll in system32 or syswow folder and restarting machine I don't UWP app OfflineFacialLogin is not launching, what could be reason

I want to OfflineFacialLogin will be firing up during the windows login, so I have written above code snippet on successful login and then launching UWP app

If you want to start the UWP application from the command line, you need to set an alias for the UWP application instead of waking up by calling the exe file.

Command-Line Activation of Universal Windows Apps

According to your description, you want to start the UWP application after booting, this can be done through StartupTask .

StartupTask

package.appxmanifest

<Package xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" ...>
...
<Applications>
    <Application ...>
        ...
        <Extensions>
          <uap5:Extension Category="windows.startupTask">
            <uap5:StartupTask
              TaskId="MyStartupId"
              Enabled="false"
              DisplayName="Test startup" />
          </uap5:Extension>
      </Extensions>
    </Application>
</Applications>

The following code creates a StartupTask:

StartupTask startupTask = await StartupTask.GetAsync("MyStartupId"); // Pass the task ID you specified in the appxmanifest file
switch (startupTask.State)
{
    case StartupTaskState.Disabled:
        // Task is disabled but can be enabled.
        StartupTaskState newState = await startupTask.RequestEnableAsync(); // ensure that you are on a UI thread when you call RequestEnableAsync()
        Debug.WriteLine("Request to enable startup, result = {0}", newState);
        break;
    case StartupTaskState.DisabledByUser:
        // Task is disabled and user must enable it manually.
        MessageDialog dialog = new MessageDialog(
            "You have disabled this app's ability to run " +
            "as soon as you sign in, but if you change your mind, " +
            "you can enable this in the Startup tab in Task Manager.",
            "TestStartup");
        await dialog.ShowAsync();
        break;
    case StartupTaskState.DisabledByPolicy:
        Debug.WriteLine("Startup disabled by group policy, or not supported on this device");
        break;
    case StartupTaskState.Enabled:
        Debug.WriteLine("Startup is enabled.");
        break;
}

App.xaml.cs

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    ...
    if (e.Kind == ActivationKind.StartupTask)
    {
        // DO SOMTHING
    }
    ...
}

By adding StartupTask , after the user allows, the system will automatically start the UWP application after login.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM