Need help with joining domain

P

Paul Steele

I am writing a C# program to automate the deployment of new notebooks the
first time they are booted after sysprep has done it's thing. I want to join
the notebook to our domain and give it a specific name based on user input.
The two functions I am using for this purpose are NetJoinDomain and
NetRenameMachineinDomain. This is basically what I'm doing:

NetJoinDomain("", domain, "OU=Notebooks,DC=ad,DC=acadiau,DC=ca", username,
password, NETSETUP_JOIN_DOMAIN | NETSETUP_ACCT_CREATE |
NETSETUP_DEFER_SPN_SET);

NetRenameMachineInDomain("", computerName, username, password,
NETSETUP_ACCT_CREATE);

The call to the first function works properly. The call creates a computer
account in the OU indicated and joins the computer to the specified domain.
The call to the rename function almost works as well. The domain account is
renamed with the new computer name, but the function returns error code 2221
and does not rename the local computer name to match the new domain name.
Error code 2221 is define as "The username could not be found". There is no
indication what the username it's complaining about, but I can only assume
that it's the domain username and password.

If I reboot the computer between calls to NetJoinDomain and
NetRenameMachineInDomain, the rename works properly. However, there is no
indication that a reboot is required after calling NetJoinDomain before
using
NetRenameMachineInDomain. I want to avoid excessive reboots to make the
process go more quickly for the user.

If anyone has used these functions in a similar situation and has any
suggestions, I'd appreciate hearing from you. Thanks.
 
E

Eric Cadwell

I haven't used these functions, but I have tried to manually do what you are
attempting and failed.
I believe you should be renaming the local machine first, then joining it to
the domain.

-Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top