问题描述:操作系统
在WiX中须要判断某个站点是否存在,WiX没有这个能力,该怎么作呢?.net
解决方案:blog
解决方法就是写一个Custom Action来检测,实现的途径也有不少,如今想到了这么几个it
1)PowerShell 须要考虑操做系统的兼容性,只有Vista以上的操做系统才支持io
2)WMIclass
3).net 提供的库以及IIS本身的库, 注意须要区分版本兼容性
IIS 6 的代码(需引用System.DirectoryServices.dll)foreach
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()); } }
IIS 七、8 的代码 (需引用c:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll)引用
var iisManager = new ServerManager(); SiteCollection sites = iisManager.Sites; foreach (var s in sites) { Console.WriteLine(s.Name); }