【问题标题】:Unable to launch UWP app with ProcessStartInfo无法使用 ProcessStartInfo 启动 UWP 应用
【发布时间】:2020-07-15 10:33:11
【问题描述】:

我必须部署 UWP 应用程序说示例“OfflineFacialLogin”,我可以像这样从命令提示符手动启动“OfflineFacialLogin”

“C:\Windows\System32>OfflineFacialLogin”

同样的代码可以在下面的代码调试环境中工作。

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

但是在将此代码 dll 放入 system32 或 syswow 文件夹并重新启动机器后,我没有 UWP 应用程序 OfflineFacialLogin 没有启动,可能是什么原因

我想 OfflineFacialLogin 将在 windows 登录期间启动,所以我在成功登录时编写了上面的代码 sn -p 然后启动 UWP 应用程序

【问题讨论】:

    标签: c# uwp processstartinfo


    【解决方案1】:

    如果要从命令行启动UWP应用,需要为UWP应用设置一个别名,而不是通过调用exe文件来唤醒。

    Command-Line Activation of Universal Windows Apps

    根据你的描述,你想在开机后启动UWP应用,可以通过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>
    

    以下代码创建一个 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
        }
        ...
    }
    

    通过添加StartupTask,在用户允许后,系统会在登录后自动启动UWP应用。

    【讨论】:

    • @Siddhanta Rath 感谢您的回复............我已经创建了 UWP 面部登录应用程序,并尝试从自定义凭据提供程序应用程序中启动它(DotNet 项目-as登录到 windows10 的选项)。我能够在 Visual Studio IDE 中启动,但是当我部署自定义凭据管理器并重新启动机器时,我能够看到自定义提供程序窗口登录屏幕,在输入用户名和密码后,我正在尝试启动到 UWP(面部登录应用程序) ,但它没有启动。
    • 您好,如果您在.Net 项目中使用ProcessStartInfo 启动UWP 应用程序,这与从命令行启动没有区别。可以参考我提供的文档在 UWP 项目中添加别名,从代码中启动。一般来说,UWP会在受保护的WindowsApp文件夹中。
    • 我的要求是 ---------------------------------- 输入用户名和密码自定义凭据提供程序(C# 项目)启动 UWP 应用程序(OfflineFacialLogin.exe)(UWP APP)捕获面部并将回调结果发送到自定义凭据提供程序根据结果 Windows 登录应该是成功还是失败。我无法启动 OfflineFacialLogin 应用程序。因此无法捕获面部并发回结果。
    • Richard Zhang 感谢 cmets,我已添加别名。
    猜你喜欢
    • 2018-04-03
    • 1970-01-01
    • 2019-04-19
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多