Here's a gem of a script I just found recently. I've seen many requests how to do this in the past and it has worked for me so here it is:(there are other ways to restart the computer than the method used here)
I use a modified version of this script that doesn't bother to reboot and also doesn't set the registry options only if a static ip address is found (because I wanted for example: people with wins disables instead of receiving it from dhcp to be updated also)
These scripts were written by Harold Fultz and Joelle Booher atAMP Incorporated, a Tyco International Ltd. Company.
This small window doesn't present the code
dhcp.bat
-----------------------------------------------------
@ECHO OFF
IF '%OS%'=='Windows_NT' GOTO :WinNT
GOTO :Win95
:WinNT
xcopy kix32.exe %systemroot%\ /D >nul
xcopy shutdown.exe c:\*.* > NUL
%systemroot%\kix32 dhcpnt.kix
goto :END
:Win95
xcopy *.pif %windir%\pif\*.* >nul
xcopy shutdown.exe c:\*.* > NUL
xcopy kix32.exe %winbootdir%\ /D >nul
xcopy kx32.dll %winbootdir%\ /D >nul
xcopy kx16.dll %winbootdir%\ /D >nul
%winbootdir%\kix32 dhcp95.kix
:END
-----------------------------------------------------
;-----------------------------------------------------
; File - DHCP95.Kix
; Logic - Change Workstation to DHCP
; Changes - 6/8/99 (hef) Created
; 6/9/99 (jmb) Added multiple NIC Support
$ComputerName=ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName")
$HKLM = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services"
$Index = 0
$Reboot = "NO"
:Loop1
$KeyName = ENUMKEY( "$HKLM\Class\NetTrans\" , $Index )
$RC = @ERROR
$DHCPEnabled=ReadValue("$HKLM\Class\NetTrans\$KeyName","IPAddress")
$Index = $Index + 1
If $RC = 0
If $DHCPEnabled <> "0.0.0.0"
$Reboot = "YES"
;---------------------------------------------------
;Updating to DHCP...
;---------------------------------------------------
; Set DHCP Settings
$ReturnCode = WRITEVALUE( "$HKLM\Class\NetTrans\$KeyName" , "IPAddress" , "0.0.0.0" , "REG_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\Class\NetTrans\$KeyName" , "IPMask" , "0.0.0.0" , "REG_SZ")
$ReturnCode = DELVALUE( "$HKLM\Class\NetTrans\$KeyName" , "DefaultGateway")
;---------------------------------------------------
; Clear WINS, DNS, and check Enable DNS Windows Resolution in WINS
;---------------------------------------------------
$ReturnCode = WRITEVALUE( "$HKLM\VxD\MSTCP" , "EnableDNS" , "0" , "REG_SZ")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "NameServer")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "NameServer1")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "NameServer2")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "SearchList")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "Domain")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "NodeType")
$ReturnCode = DELVALUE( "$HKLM\VxD\MSTCP" , "ScopeID")
Endif
goto Loop1
Endif
;---------------------------------------------------
; Reboot the PC
;---------------------------------------------------
If $Reboot = "YES"
$rc_msg=MessageBox("DHCP configuration has been changed on your PC. Your PC WILL BE REBOOTED. Please close all applications and click OK when ready.","Reboot Pending",48)
shell '%comspec% /e:1536 /c c:\shutdown.exe /REBOOT /T:1'
Else
$rc_msg=MessageBox("No changes were made to your DHCP settings. Your PC will NOT be rebooted.","No Reboot",48)
Endif
;-----------------------------------------------------
; File - DHCPNT.Kix
; Logic - Change Workstaion to DHCP
; Changes - 6/7/99 (hef) Created
; 6/10/99 (hef) Added multiple NIC support
$ComputerName=ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\ComputerName\ActiveComputerName","ComputerName")
$HKLM = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services"
$Index = 0
$Reboot = "NO"
:Loop1
$KeyName = ENUMKEY( "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\NetworkCards\" , $Index)
$RC = @ERROR
$NicYN = 0
$NicYN = ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\NetworkCards\$Keyname","Hidden")
IF $NicYN = 1
$Index = $Index + 1
$NicYN = 0
goto Loop1
ENDIF
$NicType=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\NetworkCards\$KeyName","ServiceName")
$DHCPEnabled=ReadValue("$HKLM\$NicType\Parameters\TCPIP","EnableDHCP")
$Index = $Index + 1
If $RC = 0
IF $DHCPEnabled <> "1"
$Reboot = "YES"
;---------------------------------------------------
;Updating to DHCP...
;---------------------------------------------------
;---------------------------------------------------
; Set DHCP Settings
;---------------------------------------------------
$ReturnCode = WRITEVALUE( "$HKLM\$NicType\Parameters\TCPIP" , "EnableDHCP" , "1" , "REG_DWORD")
$ReturnCode = WRITEVALUE( "$HKLM\$NicType\Parameters\TCPIP" , "IPAddress" , "0.0.0.0" , "REG_MULTI_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\$NicType\Parameters\TCPIP" , "SubnetMask" , "0.0.0.0" , "REG_MULTI_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\$NicType\Parameters\TCPIP" , "DefaultGateway" , "" , "REG_MULTI_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\DHCP" , "Start" , "2" , "REG_DWORD")
;---------------------------------------------------
; Clear WINS, DNS, and check Enable DNS Windows Resolution in WINS
;---------------------------------------------------
$ReturnCode = WRITEVALUE( "$HKLM\NetBT\Adapters\$NicType" , "NameServer" , "" , "REG_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\NetBT\Adapters\$NicType" , "NameServerBackup" , "" , "REG_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\NetBT\Parameters" , "EnableDNS" , "1" , "REG_DWORD")
$ReturnCode = WRITEVALUE( "$HKLM\TCPIP\Parameters" , "NameServer" , "" , "REG_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\TCPIP\Parameters" , "SearchList" , "" , "REG_SZ")
$ReturnCode = WRITEVALUE( "$HKLM\TCPIP\Parameters" , "Domain" , "" , "REG_SZ")
Endif
goto Loop1
Endif
;---------------------------------------------------
; Reboot the PC
;---------------------------------------------------
If $Reboot = "YES"
shell '%comspec% /c c:\shutdown.exe /REBOOT /T:1'
Endif