コード例 #1
0
ファイル: Session.cs プロジェクト: naderm1991/tutorial-wix
        /// <summary>
        /// Retrieves product properties (not session properties) from the product database.
        /// </summary>
        /// <returns>Value of the property, or an empty string if the property is not set.</returns>
        /// <remarks><p>
        /// Note this is not the correct method for getting ordinary session properties. For that,
        /// see the indexer on the Session class.
        /// </p><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msigetproductproperty.asp">MsiGetProductProperty</a>
        /// </p></remarks>
        public string GetProductProperty(string property)
        {
            if (String.IsNullOrEmpty(property))
            {
                throw new ArgumentNullException("property");
            }

            this.ValidateSessionAccess();

            StringBuilder buf     = new StringBuilder();
            uint          bufSize = (uint)buf.Capacity;
            uint          ret     = NativeMethods.MsiGetProductProperty((int)this.Handle, property, buf, ref bufSize);

            if (ret == (uint)NativeMethods.Error.MORE_DATA)
            {
                buf.Capacity = (int)++bufSize;
                ret          = NativeMethods.MsiGetProductProperty((int)this.Handle, property, buf, ref bufSize);
            }

            if (ret != 0)
            {
                throw InstallerException.ExceptionFromReturnCode(ret);
            }
            return(buf.ToString());
        }