/// <summary>
/// 服务器IIS版本
/// </summary>
public enum WebServerTypes
{
/**//// <summary>
/// 未知版本
/// </summary>
Unknown,
/**//// <summary>
/// IIS 4.0
/// </summary>
IIS4,
/**//// <summary>
/// IIS 5.0,5.1
/// </summary>
IIS5,
/**//// <summary>
/// IIS 6.0
/// </summary>
IIS6,
/**//// <summary>
/// IIS 7.0
/// </summary>
IIS7
}
public class IISHelper
{
/**//// <summary>
/// 获取服务器IIS版本
/// </summary>
/// <param name="DomainName"></param>
/// <returns></returns>
public WebServerTypes GetIISServerType(string DomainName)
{
DomainName = "LOCALHOST";
string path = "IIS://" + DomainName + "/W3SVC/INFO";
DirectoryEntry entry = null;
try
{
entry = new DirectoryEntry(path);
}
catch
{
return WebServerTypes.Unknown;
}
int num = 5;
try
{
num = (int)entry.Properties["MajorIISVersionNumber"].Value;
}
catch
{
return WebServerTypes.IIS5;
}
switch (num)
{
case 6:
return WebServerTypes.IIS6;
case 7:
return WebServerTypes.IIS7;
}
return WebServerTypes.IIS6;
}
}
IIS5.0中没有(int)entry.Properties["MajorIISVersionNumber"].Value;属性,将抛出异常
转载自:
http://kenchell.blog.163.com/blog/static/26088309200811215736216/