Hello @Anderson Rodrigues Cavalcante ,
Welcome to Microsoft Q&A!
The WinUI3 project declares runFullTrust by default, so it worked.
If you want to call AppInstallManager
from a UWP project, you need to declare runFullTrust capabilities and use Windows Application Packaging Project to package UWP and fulltrustprocess APP, then execute AppInstallManager
in fulltrustprocess.
In your UWP solution, add a “Windows Classic Desktop” project to implement your extension. I am adding a C# Console project. Next you need to add a “Windows Application Packaging Project”.
Now to connect the two projects we need to declare the extension in the package manifest. For this open the Package.appxmanifest file in the Packaging project (“WapProjTemplate1”) in XML editing mode and add the following section within the <Application> node:
<Extensions>
<desktop:Extension
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
Category="windows.fullTrustProcess"
Executable="ConsoleApp1\ConsoleApp1.exe" />
</Extensions>
To invoke the extension, we are using the FullTrustProcessLauncher API from the UWP Desktop Extension SDK. Please add Windows Desktop Extension for the UWP in UWP project
In your UWP app code, add a line of code to invoke the desktop extension component. You can place the code below in the button click event.
if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
{
await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
}
In Console App, Select Target OS version to 10.0.xxxxx.0
, add the code below in Program.cs.
using Windows.ApplicationModel.Store.Preview.InstallControl;
Console.WriteLine("Hello, World!");
string productId = "9WZDNCRFHVFW"; //Microsoft News
string skuId = "0010";
AppInstallManager installManager = new AppInstallManager();
var res = await installManager.StartAppInstallAsync(productId, skuId, false, false);
Console.WriteLine("App installation started.");
Set the WAPP("WapProjTemplate1") as the startup project, then you can debug the code.
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.