winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

LocalServerInstanceInitializer.cs (1527B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 
      4 namespace Microsoft.Management.Deployment.Projection
      5 {
      6     using Microsoft.Management.Deployment.Projection.Initializers;
      7     using WinRT;
      8 
      9     // Out-of-process COM instance initializer.
     10     public class LocalServerInstanceInitializer : PolicyEnforcedInstanceInitializer
     11     {
     12         /// <summary>
     13         /// Out-of-process context.
     14         /// </summary>
     15         public override ClsidContext Context => UseDevClsids ? ClsidContext.OutOfProcDev : ClsidContext.OutOfProc;
     16 
     17         /// <summary>
     18         /// Allow lower trust registration.
     19         /// This is useful when running COM client with admin privileges. (e.g. E2E tests)
     20         /// </summary>
     21         public bool AllowLowerTrustRegistration { init; get; }
     22 
     23         /// <summary>
     24         /// Use Prod or Dev Clsids
     25         /// </summary>
     26         public bool UseDevClsids { init; get; }
     27 
     28         /// <summary>
     29         /// Create instance of the provided type.
     30         /// </summary>
     31         /// <typeparam name="T">Projected class type.</typeparam>
     32         /// <returns>Instance of the provided type.</returns>
     33         protected override T CreateInstanceInternal<T>()
     34         {
     35             var clsid = ClassesDefinition.GetClsid<T>(Context);
     36             var iid = ClassesDefinition.GetIid<T>();
     37 
     38             var instanceInPtr = ComUtils.CoCreateInstanceLocalServer(clsid, iid, AllowLowerTrustRegistration);
     39             return MarshalGeneric<T>.FromAbi(instanceInPtr);
     40         }
     41     }
     42 }