Using DirectoryEntry to Enumerate IIS Configuration Data, Getting COMException


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)

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!

asked on Stack Overflow Sep 23, 2010 by Michael Gorsuch • edited Sep 23, 2010 by Michael Gorsuch

1 Answer


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.

answered on Stack Overflow Sep 23, 2010 by Michael Gorsuch

User contributions licensed under CC BY-SA 3.0