HOWTO: Enable DHCP Automatically Using WSH VBScript
ID: Q197424
|
The information in this article applies to:
-
Microsoft Visual Basic, Scripting Edition, version 3.0
-
Microsoft Windows 95
-
Microsoft Windows 98
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://msdn.microsoft.com/scripting
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.
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.
REFERENCES
Additional information on Windows Script Host and VBScript Language
Reference can be found on the following Web site:
http://msdn.microsoft.com/scripting
Additional query words:
IP SCRIPT DHCP
Keywords : kbVBScript300 kbWinOS95 kbWinOS98 kbWSH
Version : WINDOWS:3.0,95
Platform : WINDOWS
Issue type : kbhowto