Connect to IIS metabase on a remote 2008 server


I have written a bit of code that inspects the iis metabase to see what sites are installed and where their virtual directories are kept. THis code runs fine when run locally on the server.

I am trying to extend it so that it works remotely. The thing I'm struggling with getting it to authenticate. I'm currently using the LogonUser api, but this always returns false on logon

  • I know the credentials I have are good
  • I don't have a firewall between me and the server
  • If I run the app with out the LogonUser API call and user runas from the command line I get the error: COMException (0x80005000)

Any thoughts would be appreciated.

asked on Stack Overflow Feb 11, 2010 by ilivewithian

1 Answer


Normally if you're performing programmatic administration on a remote server you'd pass the credentials to the API. For example if you're using System.DirectoryServices then you'd do:

string server = "MyHost";
string username = "bob";
string password = "bob123$";
string path = "IIS://" + server + "/W3SVC/1";

DirectoryEntry de = new DirectoryEntry(path, username, password);
answered on Stack Overflow Feb 11, 2010 by Kev

User contributions licensed under CC BY-SA 3.0