Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9089
  • Last Modified:

Rename and join domain without rebooting in between.

Okay.  In Windows NT 4.0, I was able to rename a PC and then rejoin the domain without rebooting in between the PC rename.  For example, I would finish re-imaging a PC, then rename the PC, then join the domain on a fly.  In Windows 2000 Pro, it doesn't allow me to do that.  Once I rename the PC, I have to reboot.  Then I log back in, and rejoin the domain.  Just wondering if anyone knew of a way or a utility that does the join of the domain in Windows 2000 after the PC is renamed without rebooting in between the renaming and rejoining domain?

Thank you all in advance.

Henry
0
yackko
Asked:
yackko
  • 5
  • 3
1 Solution
 
JMansfordCommented:
Annoying isn't it.  Unfortunately I've not found an answer to this.  Therefore I'm adding this response so I get notified of the response.
0
 
JLFitzCommented:
Since you mention imaging, try using MS's sysprep. For full documentation go here http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/windows2000pro/deploy/depopt/sysprep.asp

In short once you have a system ready to image you will run sysprep on it which will shut the machine down. Image system. When the system restarts, you will be presented with a mini-setup wizzard that will allow you to change the pc name and join a domain with only one reboot.
You can even modify the sysprep.ini to provided automated answers.

NOTE: Make sure you have your product key handy because it will ask for it on reboot. (The product key can be put into the sysprep.ini for automation.)
0
 
JLFitzCommented:
I just verified that name change and domain membership can be changed in one reboot using W2K Pro SP1.

Right click My computer
Select Properties
Select Network Identification Tab
Select Properties
Change Computer Name
Change Domain Membership
Click OK all the way out and reboot.

I took PCname1 in the WORKGROUP, changed it to PCname2 as member of NT4.DOMAIN.ONE, and rebooted.
I then took that same PCname2, changed it to PCname3 as a member of W2K.DOMAIN.ONE, and rebooted.

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
yackkoAuthor Commented:
Well let me clarify.  I'm using SysPrep after the image is done.  SysPrep runs fine, but I don't want it to join the domain when it's done.  So I wrote a script to rename the PC to what it's suppose to be.  Unfortunately it needs to reboot after that.  Then the script fires up again and it use NETDOM to join the domain, then reboot.  What I want to do is to have the script rename the PC and join the domain in one session.  Instead of rebooting in between naming and joining domain.  

I did try to leave the PC in the domain, SysPrep it, burn the image, and load the image on the client machine.  The only problem is SysPrep rips the domain out.  I've tried everything.  Anymore help is appreciated.

Thanks again.
0
 
JLFitzCommented:
After reading through your previos questions, I have a better understanding of what you're trying to accomplish. I have not done anything like this so all I have left to offer is a couple suggestions.

Try this (if you havn't already):
Have sysprep join domain automaticly with autoname.
(Not sure if reboot will required before running your wsname script for this next step to work?)
Try using the /RCID switch along with the /RDF and /DFK switches. Don't forget the /USER and /PASS switches.

PS: The WSNAME utility looks pretty handy I'll have to check it out.
0
 
yackkoAuthor Commented:
Yeah the WSNAME is a pretty good utility.  It works great, but not in a script.  I've tried all the switches, but none work.  I did find another utility that is a little bit better within a script.  It's "Compname" and you can find it at http://www.willowhayes.co.uk/.  Really nice utility and nice author.

I'm found this script but just wondering how I can incorporate one of these rename and rejoin util into the WSH script?  For "Compname" to look for the data text file the syntax is: Compname /c /file:c:\netbios.txt ?i ?l ?k ?j

The ?i ?l ?k ?j is the look up param which is using the IP to look up the netbios name in the text file.  Here is the script I found:

'==========================================================================
'
' VBScript Source File
'
' NAME: computer_rename.vbs
'
' AUTHOR: Bradly T. Bolin
' DATE  : 4/5/2001
'
' COMMENT: Removes computer from an NT domain, renames it, then rejoins it
'  Requires NETDOM.EXE from Windows 2000 Resource Kit
'
'==========================================================================

Option Explicit      

Dim oFileSystem 'Scripting Dictionary object
Dim oWshShell 'Windows Script Host Shell object
Dim sCurrentName 'holds computername environment variable
Dim oWshEnvironment 'Windows Script Host environment object
Dim sTempDir 'temporary directory of computer on which comprename.vbs is run
Dim sPHASE 'holds number indicating PHASE in rename operation
Dim sProgram 'name of this script
Dim sProgramDir 'Path to this script

Set oFileSystem = CreateObject("Scripting.FileSystemObject")
Set oWshShell = CreateObject("WScript.Shell")
Set oWshEnvironment = oWshShell.Environment("Process")


sCurrentName = oWshEnvironment("COMPUTERNAME")
sTempDir = oWshEnvironment("TEMP")
sProgram = "computer_rename.vbs"
sProgramDir = oFileSystem.GetAbsolutePathName(".")

On Error Resume Next

sPHASE = oWshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Phase")

Select Case  sPHASE
      Case ""
            Call REMOVE 'Subroutine
      Case "1"
            Call REJOIN 'Subroutine
End Select
      
'Restart computer
Dim OpSysSet, OpSys
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each OpSys In OpSysSet
OpSys.Reboot()
Next
WScript.Quit
      
'REMOVE Subroutine:  Remove computer from domain, rename it and restart it

Sub REMOVE
      'Create Dictionary (key: Name, item: NewName) and load data into it
      Dim oCompName, oTextStream, sArray, sLine, sNewName
      Dim oDictionary 'VBScript Dictionary Object
      
      Set oDictionary = CreateObject("Scripting.Dictionary")
      Set oCompName = oFileSystem.GetFile(sProgramDir & "\" & "compname.txt")
      Set oTextStream = oCompName.OpenAsTextStream(1)

      Do While Not oTextStream.AtEndOfStream
            sLine = oTextStream.ReadLine
            sArray = Split(sLine, " = ", -1, 1)
            ' sArray(0) contains NAME.
            ' sArray(1) contains NEWNAME.
            oDictionary.Add sArray(0), sArray(1)
            Loop
               oTextStream.Close
      
      'Abort if computer is NOT in list of those to be renamed
      If oDictionary.Exists(sCurrentName) = FALSE Then
            MsgBox("Error")
            WScript.Quit
      End If
      'It's OK to proceed, so retrieve new computer name and place in variable sNewName
      sNewName = oDictionary.Item(sCurrentName)
      'Copy files necessary for the rename operation to local machine
      oFileSystem.CopyFile sProgramDir & "\" & sProgram, sTempDir & "\" & sProgram
      oFileSystem.CopyFile sProgramDir & "\" & "NETDOM.EXE", sTempDir & "\" & "NETDOM.EXE"
      'Backup user logon name to PreviousName value
      Dim sUserName
      sUserName = oWshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName")
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\PreviousUser", sUserName
      'Increment PHASE value
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Phase", 1
      'Place reference to program in RunOnce key
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RUN_RENAME", sTempDir & "\" & sProgram
      'Enable AutoAdminLogon
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", 1
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", "XXX"
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword", "XXX"
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", sNewName

      'Execute NETDOM REMOVE
      oWshShell.Run sTempDir & "\" & "NETDOM.EXE REMOVE " & sCurrentName & " /D:XXX /Ud:XXX /Pd:XXX", 1, TRUE
      'Rename computer
      oWshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", sNewName
      oWshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", sNewName
End Sub

'REJOIN Subroutine: Rejoin computer to the domain and clean some stuff up

Sub REJOIN
      'Restore previous user logon name from PreviousUser Value
      Dim sUserName
      sUserName = oWshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\PreviousUser")
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", sUserName
      'Delete PHASE value
      oWshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Phase"
      'Disable AutoAdminLogon
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon", 0
      oWshShell.RegDelete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword"
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultDomainName", "XXX"
      'Place clean-up routine in RunOnce key
      Dim sCMD
      sCMD = "c:\winnt\system32\"
      oWshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RUN_CLEANUP", sCMD & "CMD.EXE /c DEL " & sTempDir & "\" & sProgram
      'Execute NETDOM JOIN
      oWshShell.Run sTempDir & "\" & "NETDOM.EXE JOIN " & sCurrentName & " /D:XXX /Ud:XXX /Pd:XXX", 1, TRUE
End Sub

======================================================
Thanks again in advance.
0
 
JLFitzCommented:
After reading through your previos questions, I have a better understanding of what you're trying to accomplish. I have not done anything like this so all I have left to offer is a couple suggestions.

Try this (if you havn't already):
Have sysprep join domain automaticly with autoname.
(Not sure if reboot will required before running your wsname script for this next step to work?)
Try using the /RCID switch along with the /RDF and /DFK switches. Don't forget the /USER and /PASS switches.

PS: The WSNAME utility looks pretty handy I'll have to check it out.
0
 
JLFitzCommented:
RE: comment by me posted at 03/05/2003 10:40AM PST

Don't know how that got posted a second time? Maybe when I refreshed the page to see yacko's comment.
0
 
yackkoAuthor Commented:
Found a solution to the problem.  Thank you all for your help.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now