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



我不得不部署UWP应用程序,比如说"OfflineFacialLogin",我可以像一样从命令提示符手动启动"OfflineFacialLogin

"C:\Windows\System32>OfflineFacialLogin">

和相同的代码使用以下代码调试环境。

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

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

我想OfflineFacialLogin将在windows登录期间启动,所以我写了上面关于成功登录的代码片段,然后启动UWP应用程序

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

通用Windows应用程序的命令行激活

根据您的描述,您希望在启动后启动UWP应用程序,这可以通过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;
}

应用程序.xaml.cs

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

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

最新更新