尝试从服务配对两个WiFi Direct设备时,PairAsync()失败并出现AccessDenied错误 [英] PairAsync() fails with AccessDenied error when trying to pair two WiFi Direct devices from a service

查看:200
本文介绍了尝试从服务配对两个WiFi Direct设备时,PairAsync()失败并出现AccessDenied错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 


我已根据WiFi Direct的UWP应用程序为WiFi Direct编写了Windows服务。但是当我尝试连接两台WiFi Direct设备时, WiFi Direct 服务端的配对失败。函数DeviceInformationCustomPairing.PairAsync()
失败,状态为AccessDenied(您的应用程序没有相应的权限级别来配对设备对象)。使用UWP应用程序时,未发现问题。怎么修好?如何为服务提供
适当的权限级别来配对?


谢谢&问候,


沙林

解决方案

嗨沙林,


<感谢您在此处发帖。


>> PairAsync()在尝试访问时因AccessDenied错误而失败从服务中配对两个WiFi Direct设备


问题在于RuntimeBroker进程,UWP API通过该进程与bthserv中托管的COM蓝牙后端进行通信。

在调用PairAsync时,它会检查调用者应用程序是否在AppContainer中。为此,它使用NtOpenProcess打开进程,获取进程令牌并检查TokenIsAppContainer令牌信息字段。但是,问题是RuntimeBroker在非高速用户帐户下启动
,因此无法打开提升的服务进程。 NtOpenProcess失败并带有STATUS_ACCESS_DENIED,并且此结果被转发给PairAsync调用者。


对于这种情况,我建议您将 PairAsync调用运行到单独的进程中,从用户会话开始。也许这可以帮助你。


最好的问候,


Baron Bi


Hi, 

I have written a Windows service for WiFi Direct, based on UWP application for WiFi Direct. But when I am trying to connect two WiFi Direct devices, pairing fails on the WiFi Direct service side. The function DeviceInformationCustomPairing.PairAsync() fails with the status AccessDenied (Your application does not have the appropriate permissions level to pair the device object). With the UWP application the issue is not observed. How it can be fixed? How to provide the service with appropriate permission level to pair?

Thanks & Regards,

Sarin

解决方案

Hi Sarin,

thanks for posting here.

>>PairAsync() fails with AccessDenied error when trying to pair two WiFi Direct devices from a service

The problem is in RuntimeBroker process, through which UWP APIs communicates with COM Bluetooth backend hosted in bthserv.
While calling PairAsync it check whether caller application is in AppContainer. To do that it opens process with NtOpenProcess, gets process token and checks TokenIsAppContainer token information field. However, the problem is that RuntimeBroker is launched under nonelevated user account, so it can't open elevated service process. NtOpenProcess fails with STATUS_ACCESS_DENIED and this result is forwared to PairAsync caller.

For this case, I suggest you run PairAsync call into separate process, which start in user session. Maybe this could be help of you.

Best Regards,

Baron Bi


这篇关于尝试从服务配对两个WiFi Direct设备时,PairAsync()失败并出现AccessDenied错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆