Adding Domain User to local group in C# Com Exception RRS feed

  • Question

  • User-973006389 posted


    i have to add a domain user to local administrators group but i am getting the following error COM EXCEPTION Unhandled Unknown error (0x80005000)

    please see the code below

    DirectoryEntryAD = new DirectoryEntry("WINNT//:chd12323,computer");

    DirectoryEntry grp;

    grp = AD.Children.Find("Guests", "group");

     if (grp != null)

    { grp.Invoke("Add",<Username>); }

    it throws the error at the underlined line COM EXCEPTION unhandled.

    please help...thanks in advance

    Thursday, July 9, 2009 7:08 AM

All replies

  • User-517928126 posted

     try passing the directory object a user name and password with the appropriate permissions, as in...

    using (objAD = new DirectoryEntry())
        objAD.Path = "WinNT://" + Environment.MachineName + ",Computer";
        objAD.Username = "yourWindowsUser";
        objAD.Password = "yourPassword";
    p.s. - wrapping in a "using" will ensure the object is cleaned up properly - otherwise call dispose or close on the object when you are done. 




    Tuesday, July 14, 2009 3:46 PM
  • User-973006389 posted

    i found the error..

    we cannot use both LDAP and WinNT providers for a common operation.

    i replaced LDAP with WinNT and binded the object with WinNT now and its working..

    Thursday, July 16, 2009 7:52 AM