|Change from Static IP to DHCP|
By: Rod Trent
Posted On: 1/30/2002
This VB Script uses reg writes to change the TCP/IP options from static IP to DHCP.
Copy and paste the following script (between the lines) into Notepad, making sure to have Word Wrap disabled, then save it with a .vbs extension.
'Changes Windows NT clients from using static IP address's to use DHCP. Could be called from the logon script. Combined with the use of the SU utility this could be added to a logon script to perform a hands off migration.
'All variables declared
Dim sNIC, sMan
Set oWSHShell = WScript.CreateObject("WScript.Shell")
' Set the DCHP service to autostart
oWSHShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\DHCP\Start", 2
' Get Network card
On Error Resume Next
iCount = 1
sNIC = oWSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & iCount & "\ServiceName")
sMan = oWSHShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & iCount & "\Manufacturer")
' Skip the Async and NDIS services
If sMan <> "Microsoft" And Err.Number = 0 Then
iCount = iCount + 1
Loop Until Err.Number <> 0
' Clear the error
' End of Script
' Set the NIC service to use DHCP
sNIC = "HKLM\SYSTEM\CurrentControlSet\Services\" & sNIC &"\Parameters\TCPIP\"
iTest = oWSHShell.RegRead(sNIC & "EnableDHCP")
If iTest = 0 Then
oWSHShell.RegWrite sNIC & "EnableDHCP", 1, "REG_DWORD"
oWSHShell.RegWrite sNIC & "IPAddress", "0.0.0.0", "REG_MULTI_SZ"
oWSHShell.RegWrite sNIC & "SubnetMask", "0.0.0.0", "REG_MULTI_SZ"
NOTE: Make sure you have the latest scripting engines on the workstation you run this script from. Download the latest scripting engines here: Microsoft Scripting Home Page
When working with the Active Directory Services Interface (ADSI), you must have the same applicable rights as you would using the built-in administrative tools.
For VB Scripts that interact with Windows Management Instrumentation (WMI), apply the most current version of the WMI agents. They are downloadable here: MSDN WMI SDK.
Also, for key WMI fields such as serial number and asset tag, the computer must be SMBios 2.1 compatible.
For more information on SMBios, see the Desktop Management Task Force (DMTF) website: DMTF. If you are curious if you're computers are SMBios compliant, check with the computer's manufacturer.
For scripts that interact with the file system, you can learn more about the file system object (fso) from Microsoft's FileSystemObject User's Guide: FileSystemObject User's Guide