WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Rename a Computer using NETDOM

Keywords: 	  NETDOM

I have over 3,000 work stations to support. I was looking for a way to rename a NT workstation with out the problem of rebooting. I had tried a few things to do this and nothing seemed to work well.

So I have used WB along with the Netdom utility to do it.

There are a few things that would have to be edited for each work place but for the most part it should work OK.

Below is the wbt file and the exe that contains the Netdom app.

AddExtender("WWWNT34I.DLL")

:start

reg="SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName" 
reg2="SYSTEM\ControlSet001\Control\ComputerName\ComputerName"
State = 0 

name=Askline("Computer Name Change","Please Enter New Computer Name.","")

info=WinSysInfo()
 computername=ItemExtract(1,info,@tab)


PDC=wntGetDc( "", "FACS", 1)


info2=wntServerType(name)
 if info2 > 0
  Message("Computer Name Change","The computer name %name% is already being used. Please chose a new computer name!")
   goto start:
exit

else
regkey=RegOpenKey(@REGMACHINE, reg) 
 RegSetvalue(regkey,"[ComputerName]",name) ; This is the new key that will be created.
  RegCloseKey(RegKey) ; The batch will now close the Reg key.
  
regkey2=RegOpenKey(@REGMACHINE, reg2) 
 RegSetvalue(regkey2,"[ComputerName]",name) ; This is the new key that will be created.
  RegCloseKey(RegKey2) ; The batch will now close the Reg key.
  
 req=wntSvcStatus("", "Net Logon", 0, 0)
  if req != 1 then goto CB:  
   state=wntsvcstatus("", "Net Logon", 0,2)
    if state != 1
     wntsvccontrol("","Net Logon",0,1)
 endif

 While state != 1 
  Timedelay(1)
   state=wntsvcstatus("", "Net Logon", 0, 2)
 endwhile

 ;message("Net Logon", "Service should be stopped now.")

 ;***** Computer Browser *****
 :CB
 req=wntSvcStatus("", "Computer Browser", 0, 0)
  if req != 1 then goto serv:  
   state=wntsvcstatus("", "Computer Browser", 0,2)
    wntsvccontrol("","Computer Browser",0,1)
 
 While state != 1 
  Timedelay(1)
   state=wntsvcstatus("", "Computer Browser", 0, 2)
 endwhile

 ;message("Computer Browser", "Service should be stopped now.")

 ;**** Server ****
 :serv
 req=wntSvcStatus("", "Server", 0, 0)
   if req != 1 then goto Mes:  
    state=wntsvcstatus("", "Server", 0,2)
     if state != 1
      wntsvccontrol("","Server",0,1)
 endif

 While state != 1 
  Timedelay(1)
   state=wntsvcstatus("", "Server", 0, 2)
 endwhile

 ;message("Server", "Service should be stopped now.")

 ;***** Messager ******
:Mes
req=wntSvcStatus("", "Messenger", 0, 0)
 if req != 1 then goto Works:  
  state=wntsvcstatus("", "Messenger", 0,2)
   if state != 1
    wntsvccontrol("","Messenger",0,1)
 endif

 While state != 1 
  Timedelay(1)
   state=wntsvcstatus("", "Messenger", 0, 2)
 endwhile

 ;message("Messenger", "Service should be stopped now.")

 ;**** Workstation ****
 :Works
 req=wntSvcStatus("", "Workstation", 0, 0)
  if req != 1 then goto last:  
   state=wntsvcstatus("", "Workstation", 0,2)
    if state != 1
     wntsvccontrol("","Workstation",0,1)
 endif

 While state != 1 
  Timedelay(1)
   state=wntsvcstatus("", "Workstation", 0, 2)
 endwhile

 ;message("Workstation", "Service should be stopped now.")
 
 
 
 ;**** Starting Net Logon ****

 req=wntSvcStatus("", "Net Logon", 0, 0)
  if req != 1 then goto CBs:  
   State=wntsvcstatus("", "Net Logon", 0,2)
    if state !=4
     wntsvcstart("", "Net Logon", 0, "", "")
 endif

 while state !=4
  timedelay(1)
   state=wntsvcstatus("", "Net Logon", 0,2)
 endwhile

 ;Message("Net Logon", "Server should be started now.")

;***** Starting Computer Browser *****
 
 :CBs
 req=wntSvcStatus("", "Computer Browser", 0, 0)
  if req != 1 then goto Servs:  
   State=wntsvcstatus("", "Computer Browser", 0,2)
    if state !=4
     wntsvcstart("", "Computer Browser", 0, "", "")
 endif

 while state !=4
  timedelay(1)
   state=wntsvcstatus("", "Computer Browser", 0,2)
 endwhile

 ;Message("Net Logon", "Computer Browser should be started now.")


 ;***** Starting Server *****

 :Servs
 req=wntSvcStatus("", "Server", 0, 0)
  if req != 1 then goto Mess:  
   State=wntsvcstatus("", "Server", 0,2)
    if state !=4
     wntsvcstart("", "Server", 0, "", "")
 endif

 while state !=4
  timedelay(1)
   state=wntsvcstatus("", "Server", 0,2)
 endwhile

 ;Message("Net Logon", "Server Browser should be started now.")


 ;***** Starting Messenger ******

 :Mess
 req=wntSvcStatus("", "Messenger", 0, 0)
  if req != 1 then goto Workss:  
   State=wntsvcstatus("", "Messenger", 0,2)
    if state !=4
     wntsvcstart("", "Messenger", 0, "", "")
 endif

 while state !=4
  timedelay(1)
   state=wntsvcstatus("", "Messenger", 0,2)
 endwhile

 ;Message("Net Logon", "Messenger should be started now.")


 ;***** Starting Workstation *****

 :Workss
 req=wntSvcStatus("", "Workstation", 0, 0)
  if req != 1 then goto Last:  
   State=wntsvcstatus("", "Workstation", 0,2)
    if state !=4
     wntsvcstart("", "Workstation", 0, "", "")
 endif

 while state !=4
  timedelay(1)
   state=wntsvcstatus("", "Workstation", 0,2)
 endwhile

 ;Message("Net Logon", "Workstation should be started now.")

Display(2,"Computer Name Change","Changing Computer Name....")
 delay(3)
   RunHidewait("netdom","MEMBER \\%name% /JOINDOMAIN")
	 delay(3)
     Display(5,"Computer Name Change","Computer name has been changed to %name%.")
	   wntUserDel(PDC, "%computername%$")

:last

message("Computer Name Change","The computer name was not changed!")

Article ID:   W14959
File Created: 2001:11:08:12:41:08
Last Updated: 2001:11:08:12:41:08