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