I need to develop a program that will execute the first time Windows runs, prompt the user for a machine name, rename the machine and join it to the domain. I would like to do this without restarting the computer in between the rename and domain join steps.
The problem is that the NetJoinDomain function does not work if the computer has been renamed without restarting. Now before anyone mentions the NETSETUP_JOIN_WITH_NEW_NAME flag, it does not work on Windows XP, which is the system I'm targetting.
Now if I change the order of execution and join the computer to the domain before renaming it, I run into another problem. Active Directory does not permit duplicate machine names. This poses a big problem when there are potentially dozens of machines with the same name, all trying to join the domain at the same time.
Is there a way to solve this problem? Can XP be patched to allow NETSETUP_JOIN_WITH_NEW_NAME to work, as in Vista/Windows 7 perhaps? If not, what is the second best option?