public static string GetSidFromPackageFamilyName(string packageFamilyName) { if (string.IsNullOrEmpty(packageFamilyName)) { throw new ArgumentNullException("packageFamilyName"); } string packageSid; IAppxFactoryInternal appxInternalFactory = null; try { appxInternalFactory = (IAppxFactoryInternal)Win32InteropHelper.CoCreateInstance(new Guid(AppxInternalClassId), null, CLSCTX.INPROC, new Guid(AppxInternalInterfaceId)); if (appxInternalFactory == null) { return(null); } packageSid = appxInternalFactory.GetPackageSidFromPackageFamilyName(packageFamilyName); } finally { if (appxInternalFactory != null) { Marshal.FinalReleaseComObject(appxInternalFactory); } } return(packageSid); }
public static string GetSidFromPackageName(string packageName, string publisher) { string resultSid = null; IAppxFactoryInternal factoryInternal = null; try { factoryInternal = (IAppxFactoryInternal)Win32InteropHelper.CoCreateInstance(new Guid(AppxInternalClassId), null, CLSCTX.INPROC, new Guid(AppxInternalInterfaceId)); if (factoryInternal == null) { return(null); } var packageFamilyName = factoryInternal.GetPackageFamilyNameFromPackageId(packageName, publisher); if (!string.IsNullOrWhiteSpace(packageFamilyName)) { resultSid = factoryInternal.GetPackageSidFromPackageFamilyName(packageFamilyName); } } finally { if (factoryInternal != null) { Marshal.FinalReleaseComObject(factoryInternal); } } return(resultSid); }