Help and Support

How To Enable DHCP Automatically Using WSH VBScript

Article ID:197424
Last Review:August 8, 2007
Revision:3.4
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.
On This Page

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 (http://msdn2.microsoft.com/en-us/library/ms950396.aspx)

Back to the top

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 \\<server>\<share>\DHCP.VBS //T:5 //B
				
Where <server> is the name of the server and <share> 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.
				

Back to the top

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.
				

Back to the top

REFERENCES

Additional information on Windows Script Host and VBScript Language Reference can be found on the following Web site:
http://msdn2.microsoft.com/en-us/library/ms950396.aspx (http://msdn2.microsoft.com/en-us/library/ms950396.aspx)

Back to the top


APPLIES TO
Microsoft Visual Basic, Scripting Edition 3.0
Microsoft Windows 95
Microsoft Windows 98 Standard Edition

Back to the top

Keywords: 
kbhowto KB197424

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.