|
-
January 28th, 2005, 02:34 PM
#1
problem with NetRenameMachineInDomain
I'm trying to automate the renaming of hundreds of pc's on a domain.
I've tried using NetRenameMachineInDomain, NetJoinDomain and SetComputerNameEx.
These functions all succeed in the debugger (computer name is changed and the return values are all successful) however when I reboot and try to login under the new name the domain controller says the account doesn't exist.
Well the old and the new account do exist in active directory.
The way the network folks do this manually, is they have to remove the pc from the domain (i.e. send it to a workgroup) and reboot
then change the name and add it back into the domain and reboot again.
Is there any way to do all this programmatically? (and/or minimize the amount of rebooting??)
here's the code:
Code:
COMPUTER_NAME_FORMAT NameType;
CString s;
s = _T("NewName-001");
NameType = ComputerNamePhysicalDnsHostname;
BOOL b = SetComputerNameExA(NameType, s.operator LPCTSTR());
NET_API_STATUS nas;
// then rejoin the domain
nas = NetJoinDomain(NULL, L"mydomian", NULL, L"mydomain\\myUsername", L"mypassword" ,NETSETUP_ACCT_CREATE | NETSETUP_JOIN_DOMAIN | NETSETUP_DOMAIN_JOIN_IF_JOINED | NETSETUP_DEFER_SPN_SET);
nas = NetRenameMachineInDomain(NULL, NULL, L"mydomain\\myUsername", L"password", NETSETUP_JOIN_DOMAIN | NETSETUP_DOMAIN_JOIN_IF_JOINED);
Best Regards,
--Zim If you find this post useful, please rate it.
_________________________________
"Have you the brain worms?!?!?"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|