question

DylanSukha-0540 avatar image
0 Votes"
DylanSukha-0540 asked ·

Trouble implementing restricted capability (Packages)

So I was following this. I'm building a 'launcher' app that lets the user view and run their installed software. I managed to get this exception. It also throws some problem about getting denied by WinRT.

Exception: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at Windows.Management.Deployment.PackageManager.FindPackages() at launcherproto.MainPage..ctor()

I see a blue line under Capability that regards to referencing.

< rescap:Capability Name="packageQuery" />

Any guess on what I'm doing wrong?






windows-uwpwindows-uwp-runtime
· 4
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Are there any updates about your issue? Does my reply make sense?

0 Votes 0 ·

Ok, recently it didn't throw an exception when I replaced .FindPackages() with FindPackagesForUser("") so this isn't at all to do with admin privileges. It appears the documentation/library is faulty.
Main frustration now is that I can't call .FullName or other methods to get info unless it's a 'current' package. The only attribute I can get is the ID. Seems awfully locked down :/

0 Votes 0 ·

I'm sorry to say that this method requires admin privileges indeed. I tested this method. If I don't run the UWP app as administrator, it will throw the access denied exception as soon as I call the method.

What's more, after I consulted other engineers about this, I found that the API - Windows.Management.Deployment.PackageManager is only available from desktop apps (such as WPF). It is not available to Windows Store apps.
This is mentioned here. This should explain why you can't get the result.

You could follow this document: Call UWP APIs in desktop apps to use PackageManager class in WPF apps.


0 Votes 0 ·

Do you have any other questions about this?

0 Votes 0 ·

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered ·

Hi,

Welcome to Microsoft Q&A!

According to the document: FindPackages(String, String) Method requires administrative privileges. That's why you get the access denied exception.


· 3 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am the administrator. How do I permit my app to run with the privileges?

0 Votes 0 ·

Native UWP apps are running in Sandbox and are not allowed to run as administrator. Maybe call this API in other components like desktop apps (not sure if this) and convert it as desktop bridge app could do the magic.

To use UWP APIs in desktop apps, you could refer to Call UWP APIs in desktop apps. After that, you could use desktop bridge to package the desktop app with a UWP app. Then launch the desktop app
as administrator from the UWP app. UWP apps need to add ‘allowElevation’ capability for this.



0 Votes 0 ·

Does this help you to solve the issue?

0 Votes 0 ·