Grab our RSS feeds Follow us on Twitter Join our Facebook Group Connect with us on LinkedIn, Powered by You.
you are not logged in





Site Services

Community Forums

Discussion Lists

Article Search


Web Blogs


Live Support

myITforum TV

Take a Poll

Monthly Drawing

myITforum Network

User Group Directory

Our Partners

About Us





Industry News:

  Home : Articles : Scripting print | email | | Forums |   print | email | | Blogs |   print | email | | Wiki |   print | email | | FAQs |   print | email | Article Search  
Change from Static IP to DHCP

Bookmark and Share

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
Option Explicit

Dim oWSHShell
Dim sNIC, sMan
Dim iCount

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
Call SetNIC
End If
iCount = iCount + 1
Loop Until Err.Number <> 0

' Clear the error

' End of Script

Sub SetNIC
Dim iTest
' 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", "", "REG_MULTI_SZ"
oWSHShell.RegWrite sNIC & "SubnetMask", "", "REG_MULTI_SZ"
End If
End Sub

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 ©2010 | Legal | Privacy