/// <summary>
        /// Harvest a web site.
        /// </summary>
        /// <param name="name">The name of the web site.</param>
        /// <returns>The harvested web site.</returns>
        public IIs.WebSite HarvestWebSite(string name)
        {
            try
            {
                DirectoryEntry directoryEntry = new DirectoryEntry("IIS://localhost/W3SVC");

                foreach (DirectoryEntry childEntry in directoryEntry.Children)
                {
                    if ("IIsWebServer" == childEntry.SchemaClassName)
                    {
                        if (String.Equals((string)childEntry.Properties["ServerComment"].Value, name, StringComparison.OrdinalIgnoreCase))
                        {
                            return(this.HarvestWebSite(childEntry));
                        }
                    }
                }
            }
            catch (COMException ce)
            {
                // 0x8007005 - access denied
                // If we don't have permission to harvest a website, it's likely because we're on
                // Vista or higher and aren't an Admin.
                if ((0x80070005 == unchecked ((uint)ce.ErrorCode)))
                {
                    throw new WixException(IIsErrors.InsufficientPermissionHarvestWebSite());
                }
                // 0x80005000 - unknown error
                else if ((0x80005000 == unchecked ((uint)ce.ErrorCode)))
                {
                    throw new WixException(IIsErrors.CannotHarvestWebSite());
                }
            }

            throw new WixException(IIsErrors.WebSiteNotFound(name));
        }
Esempio n. 2
0
        /// <summary>
        /// Harvest a web site.
        /// </summary>
        /// <param name="name">The name of the web site.</param>
        /// <returns>The harvested web site.</returns>
        public IIs.WebSite HarvestWebSite(string name)
        {
            DirectoryEntry directoryEntry = new DirectoryEntry("IIS://localhost/W3SVC");

            foreach (DirectoryEntry childEntry in directoryEntry.Children)
            {
                if ("IIsWebServer" == childEntry.SchemaClassName)
                {
                    if ((string)childEntry.Properties["ServerComment"].Value == name)
                    {
                        return(this.HarvestWebSite(childEntry));
                    }
                }
            }

            throw new WixException(IIsErrors.WebSiteNotFound(name));
        }