I'm trying to make a program that makes it easier for us to deploy new computers on the domain. What I want it to do, is simply rename the computer, and join it to our domain (it's going to be doing a lot of other stuff, but this isn't coming in till I've got this working).
Code here: http://pastebin.com/ayREYH0C
Stolen from http://www.experts-exchange.com/Programming/Languages/.NET/Q_26262588.html and then changed to fit my needs
My problem is that the domain join doesn't respect the rename of the computer. I've put in a Thread.Sleep between the rename and the join so I had some time to check if the rename happens at all, and it does! When the domainjoin happens, it reverts back to the old name though and that is the computername that gets created in the domain, not the new name.
I've searched all around, but not found an issue like this, nor a solution for this particular need.
Best Answer
Here is a c# function that joins a workstation to a domain...thought you might find use of it as an alternate method that avoids WMI and uses ManagementObject instead:
(I realize that the executing credentials still need the rights to rename)