Marty
Fri Apr 07 10:55:32 CDT 2006
A couple years ago I tried to get this to work and gave up, I ended up using
NETDOM.EXE from the Windows XP Support Tools:
http://www.microsoft.com/downloads/details.aspx?FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38&DisplayLang=en
MSH C:\>netdom.exe renamecomputer
The syntax of this command is:
NETDOM RENAMECOMPUTER machine /NewName:new-name
/UserD:user [/PasswordD:[password | *]]
[/UserO:user [/PasswordO:[password | *]]]
[/Force]
[/REBoot[:Time in seconds]]
NETDOM RENAMECOMPUTER renames a computer that is joined to a domain. The
computer object in the domain is also renamed. Certain services, such as the
Certificate Authority, rely on a fixed machine name. If any services of this
type are running on the target computer, then a computer name change would
have an adverse impact.
machine is the name of the workstation, member server, or domain controller
to be renamed
/NewName Specifies the new name for the computer. Both the DNS host
label and the NetBIOS name are changed to new-name. If
new-name is longer than 15 characters, the NetBIOS name is
derived from the first 15 characters
/UserD User account used to make the connection with the domain
to which the computer is joined. This is a required parameter.
The domain can be specified as "/ud:domain\user". If domain is
omitted, then the computer's domain is assumed.
/PasswordD Password of the user account specified by /UserD. A * means
to prompt for the password
/UserO User account used to make the connection with the machine to
be renamed. If omitted, then the currently logged on user's
account is used. The user's domain can be specified as
"/uo:domain\user". If domain is omitted, then a local computer
account is assumed.
/PasswordO Password of the user account specified by /UserO. A * means
to prompt for the password
/Force As noted above, this command can adversely affect some services
running on the computer. The user will be prompted for
confirmation unless the /FORCE switch is specified.
/REBoot Specifies that the machine should be shutdown and automatically
rebooted after the Rename has completed. The number of seconds
before automatic shutdown can also be provided. Default is
30 seconds
NETDOM HELP command | MORE displays Help one screen at a time.
The command completed successfully.
"Incroyable HULK" <IncroyableHULK@discussions.microsoft.com> wrote in message
news:0DDCC46B-E5B8-4315-B182-257D9C6BA7D1@microsoft.com...
> Hello all,
>
> I want to rename a computer and then join the domain WITHOUT a reboot
>
> This code works BUT The Account created on the domain uses the old computer
> name (but the DNS Name field is using the new name).
>
> Do I have to use the MoveHere method of ADSI to apply the new name to the
> account or there is a better way?
>
> '************** RENAME **************
> NewName = "VBTest"
>
> Set objWMIService = GetObject("Winmgmts:root\cimv2")
>
> For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")
> objComputer.rename(NewName, NULL, NULL)
> Next
>
> '************** JOIN DOMAIN **************
>
> strDomain = "ActiveDirectory"
> strPassword = "password"
> strUser = "username"
>
> Set objNetwork = CreateObject("WScript.Network")
> strComputer = objNetwork.ComputerName
> Set objComputer = GetObject _
> ("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & _
> "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
> objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & _
> "\" & strUser, NULL, 1 + 2)
>
>