简体   繁体   English

我可以从 UWP 应用程序的进程外后台任务中启动 FullTrust Win32 应用程序吗?

[英]Can I launch a FullTrust Win32 app from within a UWP app's out-of-process background task?

I needed to read the registry every system login in order to determine whether to launch a notification or not.我需要在每次系统登录时读取注册表以确定是否启动通知。 So I had to create an out-of-process background task with SystemTriggerType.SessionConnected to do this.因此,我必须使用SystemTriggerType.SessionConnected创建一个进程外后台任务来执行此操作。 The background task implementation would look something like this:后台任务实现看起来像这样:

public async void Run(IBackgroundTaskInstance taskInstance)
{
    
    Task launchFullTrust = LaunchFullTrustProcessForCurrentAppAsync(); //Windows.ApplicationModel.FullTrustProcessLauncher as an async task
    launchFullTrust.Wait();

    BackgroundTaskDeferral appServiceDeferral = taskInstance.GetDeferral();
    AppServiceTriggerDetails details = taskInstance.TriggerDetails as AppServiceTriggerDetails;
    Connection = details.AppServiceConnection; // AppServiceConnection object
    ...
    // perform data acquisition
}

But because this background process is triggered by the session connectivity, it is guaranteed that taskInstance will not contain AppServiceTriggerDetails , or anything related to the AppServiceTrigger at all.但是因为这个后台进程是由 session 连接触发的,所以可以保证taskInstance不会包含AppServiceTriggerDetails或任何与AppServiceTrigger相关的内容。 Considering this, is there a way to receive a handle to the AppServiceConnection connection from the background task, and not from the UWP app itself?考虑到这一点,有没有办法从后台任务而不是从 UWP 应用程序本身接收AppServiceConnection连接的句柄?

To answer the main question if it is possible to launch a FullTrust Win32 app from an out-of-process background task: Yes要回答是否可以从进程外后台任务启动 FullTrust Win32 应用程序的主要问题:

But the Win32 app will trigger the OnBackgroundTaskActivated function of the Main UWP application.但是 Win32 应用程序将触发主 UWP 应用程序的OnBackgroundTaskActivated function。 This means it would be better to continue from said function and obtain a handle to the AppServiceConnection from there.这意味着最好从所述 function 继续并从那里获取AppServiceConnection的句柄。 I was hoping to have a way to receive the connection on the background-task itself, but this situation seems workable for me.我希望有一种方法可以接收后台任务本身的连接,但这种情况对我来说似乎可行。 I am able to continue with this approach.我能够继续使用这种方法。

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

相关问题 从主UWP进程终止UWP应用的Win32进程,或向其发送消息 - Terminate the win32 process of UWP app from main UWP process, or send message to it 如何通过后台 Win32 进程使用全局快捷方式启动 UWP 应用程序? - How to start a UWP app with a global shortcut through a background Win32 process? 我的Win32 App如何从UWP App窃取焦点? - How Can My Win32 App Steal Focus From My UWP App? 我无法在 UWP 应用程序和 Win32 应用程序之间通信 - I can't communicate between UWP app and Win32 app 从后台任务启动UWP应用 - Launch an UWP app from Background Task 在UWP中启动后台Win32控制台应用程序 - Launch background win32 console application in UWP 是否可以从 windows 任务计划程序使用/不使用命令行参数启动/触发桌面桥接应用程序 (Win32)? - Is it Possible to launch/Trigger an desktop bridged app(Win32) with/without command line parameter from windows task scheduler? 内存映射文件是否作为 uwp 应用程序和 win32 进程之间的 ipc 支持 - Is Memory-mapped-files as ipc between uwp app and win32 process supported 如何从 UWP 应用程序中使用命令行 arguments 实现启动 win32 exe? - How do you implement Launching a win32 exe with command line arguments from an UWP app? 如何从任务计划程序启动 UWP 应用程序 - How to Launch UWP app from Task Scheduler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM