Using DirectoryEntry to Enumerate IIS Configuration Data, Getting COMException

廉价感情. 提交于 2019-12-12 10:04:26

问题


I'm attempting to manage a set of remote IIS 6 server programmatically, but am running into a wall.

My client is Windows 7, and I have Domain Admin rights.

The relevant code is as follows:

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

  foreach (DirectoryEntry site in W3SVC.Children)
  {
    Console.WriteLine(site.Name);
  }
} 

When I execute, I receive the following exception:

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

I see that this is happening at Bind (which I assume is the connection attempt), but am unable to get any further info here.

Does anyone have advice? Thanks!


回答1:


Ah! It turns out that I did not have the IIS 6 management tools installed on my machine. Once I installed them, this executed as expected.



来源:https://stackoverflow.com/questions/3782058/using-directoryentry-to-enumerate-iis-configuration-data-getting-comexception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!