locked
Renaming a computer via active directory RRS feed

  • Question

  • I am using the following ADSI code to rename machines in active directory:

     

    Boolean rc = true;

    try

    {

    DirectoryEntry machineNode = null;

    //machineNode = new DirectoryEntry("WinNT://" + oldname + ",computer");

    machineNode = new DirectoryEntry("WinNT://" + oldname);

    //machineNode = new DirectoryEntry("LDAP://CN=" + oldname + ",DC=ca,DC=canwest,DC=com");

    machineNode.Username = administrator;

    machineNode.Password = administratorPassword;

    machineNode.AuthenticationType = AuthenticationTypes.Secure;

    machineNode.Rename(newname);

    //machineNode.Properties["CommonName"].Value = newname;

    machineNode.CommitChanges();

    }

    catch (Exception e)

    {

    String msg = e.Message;

    String stacktrace = e.StackTrace;

    rc = false;

    }

    return rc;

    The DirectoryEntry object is instantiated with new DirectoryEntry("WinNT://unittest3");, where unittest3 is a machine in the domain CA.

    However, the code always fails on the Rename call with an exception of "The network path was not found.  (Exception from HRESULT:0x80070035).

    What is wrong here?


    Derrick Lau
    Tuesday, March 17, 2009 3:14 PM

All replies

  • I solved the above problem but have a new one:

    I would like to change the property of an Active Directory computer object so that I can decide who can join the object to a domain.  How do I do this in C#?
    Derrick Lau
    Thursday, April 9, 2009 8:53 PM
  • How did you solved previous problem?
    RUV
    Monday, March 15, 2010 10:08 AM
  • Let's close the question? Anyone can answer?

    RUV

    Thursday, November 21, 2013 9:27 AM