I have a local user, which is member of Administrators local group.
When I run this code:
using System;
using System.DirectoryServices;
namespace nanttest
{
class Program
{
public static void Main(string[] args)
{
using(DirectoryEntry entry = new DirectoryEntry("IIS://localhost/W3SVC"))
{
object absobject = entry.NativeObject;
Console.WriteLine("Name: {0}", entry.Name);
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
}
I receive:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80070005): Access is denied.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_NativeObject() at nanttest.Program.Main(String[] args) in c:\Work\nanttest\nanttest\Program.cs:line 20
If I run this code while logged in as Administrator, it works OK.
Also, this code fails if I run it logged in as a DomainAdmin user. I have added MYDOMAIN\DomainAdmins and MYDOMAIN\mydomainuser as members of local Administrators group.
What other permissions should I add for these users, so they can run this code.