高手救命啊!使用 ADSI 操纵 IIS 出现的问题
使用 ADSI 获取 IIS 版本号有问题,在 Windows Server 2003 下正确运行,但在 Windows XP SP2 却显示下面的错误
System.NullReferenceException: Object reference not set to an instance of an object.
at IISHelper.GetIISServerType() in D:\Documents and Settings\桌面\IISMangment\IISMangment\Class1.cs:line 50
at IISMangment.Form1.Form1_Load(Object sender, EventArgs e) in D:\Documents and Settings\桌面\IISMangment\IISMangment\Form1.cs:line 24
源代码如下:
System.NullReferenceException: Object reference not set to an instance of an object.
at IISHelper.GetIISServerType() in D:\Documents and Settings\桌面\IISMangment\IISMangment\Class1.cs:line 50
at IISMangment.Form1.Form1_Load(Object sender, EventArgs e) in D:\Documents and Settings\桌面\IISMangment\IISMangment\Form1.cs:line 24
源代码如下:
using System.DirectoryServices;
using System;
/**/
/// <summary>
/// 服务器IIS版本
/// </summary>
[Serializable]
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>
/// <returns></returns>
public WebServerTypes GetIISServerType()
{
string DomainName = "LOCALHOST";
string path = "IIS://" + DomainName + "/W3SVC/INFO";
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(path);
int num = -1;
num = (int)entry.Properties["MajorIISVersionNumber"].Value;//此行代码在 Windows XP SP2 下有问题。
switch (num)
{
case 4:
return WebServerTypes.IIS4;
case 5:
return WebServerTypes.IIS5;
case 6:
return WebServerTypes.IIS6;
case 7:
return WebServerTypes.IIS7;
default:
return WebServerTypes.Unknown;
}
}
}
...全文
相关推荐
VBScript使用ADSI为IIS批量添加屏蔽或允许访问的IP
用ADSI+ASP添加IP到IIS禁止访问列表中
ADSI+ASP添加IP到IIS禁止访问列表中
注意:执行的ASP文件需要管理员权限
DirectoryEntry配置IIS7出现ADSI Error:未知错误(0x80005000)
主要介绍了DirectoryEntry配置IIS7出现ADSI Error:未知错误(0x80005000)的解决办法
用C#操纵IIS(代码)
using System; using System.DirectoryServices; using System.Collections; using System.Text.RegularExpressions; using System.Text; /** * @author 吴海燕 * @email wuhy80-usual@yahoo.com * 2004-6-25 第一版 */ namespace Wuhy.ToolBox { /// /// 这个类是静态类。用来实现管理IIS的基本操作。
delphi for adsi demo 代码
delphi操作windows ad经典代码,


