Microsoft Knowledge Base Email Alertz

(197424) - 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...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 197424 - Last Review: August 8, 2007 - Revision: 3.4

How To Enable DHCP Automatically Using WSH VBScript

System TipThis article applies to a different version of Windows than the one you are using. Content in this article may not be relevant to you. Visit the Windows Vista Solution Center
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)

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

APPLIES TO
  • Microsoft Visual Basic, Scripting Edition 3.0
  • Microsoft Windows 95
  • Microsoft Windows 98 Standard Edition
Keywords: 
kbhowto KB197424
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate