예제 #1
0
        /// <summary>
        /// Gets the set of all products with a specified upgrade code. This method lists the
        /// currently installed and advertised products that have the specified UpgradeCode
        /// property in their Property table.
        /// </summary>
        /// <param name="upgradeCode">Upgrade code of related products</param>
        /// <returns>Enumeration of product codes</returns>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msienumrelatedproducts.asp">MsiEnumRelatedProducts</a>
        /// </p></remarks>
        public static IEnumerable <ProductInstallation> GetRelatedProducts(string upgradeCode)
        {
            StringBuilder buf = new StringBuilder(40);

            for (uint i = 0; true; i++)
            {
                uint ret = NativeMethods.MsiEnumRelatedProducts(upgradeCode, 0, i, buf);
                if (ret == (uint)NativeMethods.Error.NO_MORE_ITEMS)
                {
                    break;
                }
                if (ret != 0)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }
                yield return(new ProductInstallation(buf.ToString()));
            }
        }