From 867cad5af081e47f5b2f8d954235c6be2058808f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Climent?= Date: Thu, 26 Sep 2024 00:17:00 +0200 Subject: [PATCH] Update README.md --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4673d04..c8a0d35 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,18 @@ The code on the project named `WindowsPackageManager Interop` was extracted and > [!WARNING] > The `CreateAppInstaller()` WinRT function does not exist. `CreatePackageManager()` must be used instead. -> [!CAUTION] -> If an elevated process initializes WinGet with the `WindowsPackageManagerStandardFactory()` class, the method `CreatePackageManager()` will crash. The class `WindowsPackageManagerElevatedFactory()` must be used instead +
+## ⚠️Important notes about running with admin rights⚠️ +If an elevated process initializes WinGet with the `WindowsPackageManagerStandardFactory()` class, the method `CreatePackageManager()` will crash. The class `WindowsPackageManagerElevatedFactory()` must be used instead. + +However, under certain scenarios (for example, Unpackaged, self-contained AppSdk executable with RegFree-WinRT enabled), the `WindowsPackageManagerElevatedFactory()` method may crash your program (no exception, just a hard crash, the bug report can be seen here: https://github.com/microsoft/winget-cli/issues/4377). + +In such case, it may be needed to use the `WindowsPackageManagerStandardFactory()` class, but modifying the CreateInstance method as shown [here (this is how it works on UniGetUI)](https://github.com/marticliment/UniGetUI/blob/9d73f284edfd0e9c26a2a8d3d72187180ea3af23/src/WindowsPackageManager.Interop/WindowsPackageManager/WindowsPackageManagerStandardFactory.cs#L23-L29) so that the undocumented `CLSCTX.CLSCTX_ALLOW_LOWER_TRUST_REGISTRATION` flag is passed to `PInvoke.CoCreateInstance`. + +DISCLAIMER: I am no COM expert so I don't know the potential side effects of this undocumented flag. Use at your own risk. + +
# Usage example The following example can be found on the `Demo Console App` project on this same repository.