public static void InitializeBroker() { if (IsBrokerInitialized) { return; } IsBrokerInitialized = true; // Broker is only supported on Windows 10 and later if (!PlatformUtils.IsWindowsBrokerSupported()) { return; } // Nothing to do when not an elevated user if (!PlatformUtils.IsElevatedUser()) { return; } // Lower COM security so that MSAL can make the calls to WAM int result = Interop.Windows.Native.Ole32.CoInitializeSecurity( IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, Interop.Windows.Native.Ole32.RpcAuthnLevel.None, Interop.Windows.Native.Ole32.RpcImpLevel.Impersonate, IntPtr.Zero, Interop.Windows.Native.Ole32.EoAuthnCap.None, IntPtr.Zero ); if (result != 0) { throw new Exception( $"Failed to set COM process security to allow Windows broker from an elevated process (0x{result:x})." + Environment.NewLine + $"See {Constants.HelpUrls.GcmWamComSecurity} for more information."); } }