Example #1
0
        public static string MsiGetProductInfo(Guid productCode, MsiWrapper.INSTALLPROPERTY property)
        {
            var propertyLen = 512;
            var sbProperty  = new StringBuilder(propertyLen);

            var code = MsiWrapper.MsiGetProductInfo(productCode.ToString("B"), property.PropertyName, sbProperty,
                                                    ref propertyLen);

            //if (code != 0)
            //    throw new System.IO.IOException("MsiGetProductInfo returned error code " + code);

            //If code is 0 prevent returning junk
            return(code != 0 ? null : sbProperty.ToString());
        }
Example #2
0
        public static IEnumerable <Guid> MsiEnumProducts()
        {
            var sbProductCode = new StringBuilder(39);
            var iIdx          = 0;

            while (MsiWrapper.MsiEnumProducts(iIdx++, sbProductCode) == 0)
            {
                var guidString = sbProductCode.ToString();
                if (GuidTools.GuidTryParse(guidString, out var guid))
                {
                    yield return(guid);
                }
                else
                {
                    Console.WriteLine($@"Invalid MSI guid in MsiEnumProducts: {guidString}");
                }
            }
        }
Example #3
0
        public static X509Certificate2 GetCertificate(Guid productCode)
        {
            var localPackage = MsiGetProductInfo(productCode, MsiWrapper.INSTALLPROPERTY.LOCALPACKAGE);

            if (localPackage == null || !Path.IsPathRooted(localPackage) || !File.Exists(localPackage))
            {
                return(null);
            }

            IntPtr certData;
            uint   pcb    = 0;
            var    result = MsiWrapper.MsiGetFileSignatureInformation(localPackage, 0, out certData, null, ref pcb);

            if (result == 0)
            {
                return(new X509Certificate2(certData));
            }

            return(null);
        }