Microsoft KB Archive/197424

= How To Enable DHCP Automatically Using WSH VBScript =

Article ID: 197424

Article Last Modified on 8/8/2007

-

APPLIES TO


 * Microsoft Visual Basic, Scripting Edition 3.0
 * Microsoft Windows 95
 * Microsoft Windows 98 Standard Edition

-



This article was previously published under Q197424



IMPORTANT: This article contains information about editing the registry. Before you edit the registry, make sure you understand how to restore it if a problem occurs. For information about how to do this, view the "Restoring the Registry" Help topic in Regedit.exe or the "Restoring a Registry Key" Help topic in Regedt32.exe.



SUMMARY
This article describes how to create a VBScript file that automatically enables DHCP under Windows 98 or Windows 95 using Windows Script Host.

IMPORTANT: This procedure is not intended for home users with a few computers.

Please note that if you are using Windows 95, you need to install WSH.exe from the following Web site to enable Windows Script Host:

http://msdn2.microsoft.com/en-us/library/ms950396.aspx



MORE INFORMATION
WARNING: Modifying the registry incorrectly can cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that problems resulting from the incorrect modification of the Registry can be solved. Modify the registry at your own risk.

For information about how to edit the registry, view the "Changing Keys And Values" Help topic in Registry Editor (Regedit.exe) or the "Add and Delete Information in the Registry" and "Edit Registry Data" Help topics in Regedt32.exe. Note that you should back up the registry before you edit it. If you are running Windows NT, you should also update your Emergency Repair Disk (ERD).

WARNING: The following VBScript sample provided will erase the static IP address assigned to a computer. There is no automated way to go back to static IP address after using the script provided below. There are 2 registry entries used to determine if DHCP is enabled IPAddress and IPMask. Both are set to "0.0.0.0" to enable DHCP.

Use the following line to run DHCP.vbs from a login script: Cscript \\ \ \DHCP.VBS //T:5 //B Where is the name of the server and is the name of the share. //T:5 Terminates the script after 5 seconds if it is still running. //B   Tells the script to run in non-interactive mode.

Sample Code
Using a text editor, create a VBScript file called DHCP.vbs with the following lines: '---  ' The following script reads the registry value name IPAddress to   ' determine which registry entries need to be changed to enable DHCP. ' This sample checks the first 11 network bindings for TCP/IP, which is  ' typically sufficient in most environments. ' --  Dim WSHShell, NList, N, IPAddress, IPMask, IPValue, RegLoc Set WSHShell = WScript.CreateObject("WScript.Shell")

NList = array("0000","0001","0002","0003","0004","0005","0006", _                "0007","0008","0009","0010")

On Error Resume Next RegLoc = "HKLM\System\CurrentControlSet\Services\Class\NetTrans\"

For Each N In NList IPValue = ""     'Resets variable IPAddress = RegLoc & N & "\IPAddress" IPMask = RegLoc & N & "\IPMask" IPValue = WSHShell.RegRead(IPAddress) If (IPValue <> "") and (IPValue <> "0.0.0.0") then WSHShell.RegWrite IPAddress,"0.0.0.0" WSHShell.RegWrite IPMASK,"0.0.0.0" end If  Next

WScript.Quit       ' Tells the script to stop and exit.

