Пример #1
0
 /// <summary>
 /// Enumerates all MSI installed products
 /// </summary>
 /// <returns>
 /// An enumeration containing InstalledProducts
 /// </returns>
 public static IEnumerable <InstalledProduct> EnumerateInstalledProducts()
 {
     foreach (var guid in MSI.EnumerateGUIDs())
     {
         yield return(new InstalledProduct(guid));
     }
 }
Пример #2
0
        private string TryGetProperty(string propertyName)
        {
            string propertyValue;

            if (MSI.TryGetProperty(_guid, propertyName, out propertyValue) != MsiExitCodes.Success)
            {
                propertyValue = null;
            }
            return(propertyValue);
        }
Пример #3
0
        /// <summary>
        /// Get property of a product indicated by GUID. Throws exception if cannot read the property.
        /// </summary>
        /// <param name="productGUID">Product GUID</param>
        /// <param name="PropertyName">Property name</param>
        /// <returns>Property value, if available.</returns>
        /// <exception cref="MSIException">Throws MSIException if reading property was not successful</exception>
        public static String getProperty(string productGUID, string PropertyName)
        {
            int len = 0;

            // Get the data len
            MSI.MsiGetProductInfo(productGUID, PropertyName, null, ref len);
            // increase for the terminating \0
            len++;

            String r           = new string(new char[len]);
            int    returnValue = MSI.MsiGetProductInfo(productGUID, PropertyName, r, ref len);

            if (returnValue != 0)
            {
                throw new MSIException(returnValue);
            }

            return(r);
        }
Пример #4
0
        /// <summary>
        /// Enumerate all installed product GUIDs
        /// </summary>
        /// <returns>A List of strings containing all GUIDs</returns>
        public static List <string> EnumerateGUIDs()
        {
            var  guidList = new List <string>();
            uint ret = 0, i = 0, dummy2 = 0;

            do
            {
                string GUID = new string(new char[39]);
                object dummy1;
                ret = MSI.MsiEnumProductsEx(null, null, (uint)InstallContext.All, i, GUID, out dummy1, null, ref dummy2);
                if (ret == 0)
                {
                    guidList.Add(GUID);
                }
                i++;
            } while (ret != (uint)MsiExitCodes.NoMoreItems);

            return(guidList);
        }