[Solve a problem every day series-0012] How to get IIS site information through a program

Source: Internet
Author: User

Problem Description:

In WiX you need to determine whether a site exists, WiX does not have this ability, how to do it?

Solution:

The solution is to write a custom action to detect, there are many ways to achieve, now think of so few

1) PowerShell needs to consider operating system compatibility, only the operating system above Vista is supported

2) WMI

3). NET provided libraries and IIS own libraries, note the need to differentiate between versions

Code for IIS 6 (reference System.DirectoryServices.dll required)

DirectoryEntry Services = new DirectoryEntry ("Iis://localhost/w3svc");            IEnumerator ie = Services.Children.GetEnumerator ();            DirectoryEntry Server = null;            while (ie. MoveNext ())            {                Server = (DirectoryEntry) ie. Current;                if (Server.schemaclassname = = "IIsWebServer")                {                    Console.WriteLine (server.properties["ServerComment"][0]. ToString ());                }            }

Code for IIS 7, 8 (reference C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll required)

            var iismanager = new Servermanager ();            SiteCollection sites = iismanager.sites;            foreach (var s in sites)            {                Console.WriteLine (s.name);            }        

  

[Solve a problem every day series-0012] How to get IIS site information through a program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.