使用DirectoryEntry枚举IIS配置数据,获取COMException

Mic*_*uch 2 c# iis-6

我正在尝试以编程方式管理一组远程IIS 6服务器,但我遇到了问题.

我的客户端是Windows 7,我有域管理员权限.

相关代码如下:

public void Run()
{
  DirectoryEntry W3SVC = new DirectoryEntry("IIS://server/w3svc");

  foreach (DirectoryEntry site in W3SVC.Children)
  {
    Console.WriteLine(site.Name);
  }
} 
Run Code Online (Sandbox Code Playgroud)

当我执行时,我收到以下异常:

Unhandled Exception: System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
   at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
   at System.DirectoryServices.DirectoryEntry.Bind()
   at System.DirectoryServices.DirectoryEntry.get_IsContainer()
   at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
   at System.DirectoryServices.DirectoryEntries.GetEnumerator()
   at Worker.Worker.Run() in c:\code\Worker\Worker\Worker.cs:line 31
   at Worker.Worker.Main(String[] args) in c:\code\Worker\Worker\Worker.cs:line 15
Run Code Online (Sandbox Code Playgroud)

我看到这发生在Bind(我假设是连接尝试),但我无法在这里获得任何进一步的信息.

有人有建议吗?谢谢!

Mic*_*uch 5

啊! 事实证明,我的机器上没有安装IIS 6管理工具.安装完成后,按预期执行.