简体   繁体   English

无法使用 ProcessStartInfo 启动 UWP 应用程序

[英]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我必须部署 UWP 应用程序显示示例“OfflineFacialLogin”,我可以像这样从命令提示符手动启动“OfflineFacialLogin”

“C:\Windows\System32>OfflineFacialLogin” “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但是在将此代码 dll 放入 system32 或 syswow 文件夹并重新启动机器后,我没有 UWP 应用程序 OfflineFacialLogin 没有启动,可能是什么原因

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我想 OfflineFacialLogin 将在 windows 登录期间启动,所以我在成功登录时编写了上面的代码片段,然后启动 UWP 应用程序

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.如果要从命令行启动 UWP 应用程序,则需要为 UWP 应用程序设置别名,而不是通过调用 exe 文件来唤醒。

Command-Line Activation of Universal Windows Apps 通用 Windows 应用程序的命令行激活

According to your description, you want to start the UWP application after booting, this can be done through StartupTask .根据您的描述,您想在启动后启动 UWP 应用程序,这可以通过StartupTask来完成。

StartupTask 启动任务

package.appxmanifest 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 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 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.通过添加StartupTask ,在用户允许后,系统会在登录后自动启动 UWP 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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