>Maintaining and administering Windows machines (desktops and servers of Windows make) is a time intensive and often very challenging task [Think about the last time there was a virus outbreak on your LAN machines 🙂 ].
One task which is very time consuming is the configuration of network settings on individual machines.Visiting each box to change its network settings is not at all something that excites all.
Here is a VB script that converts static IPs to a DHCP based when run on the target machines.First off,a properly configured DHCP server should be in place and secondly the target machines should be alive on the network.
The script in a nutshell will do the following things :
1.Make the DHCP service start automatically.
2.Get the network card details
3.Configure the network card to use DHCP (the obtain IP addresses automatically thingy…)
To use this script,save it as somesensiblescriptname.vbs,put it in logon script and deploy that logon script via GPO (of course we are talking about domain based environment)
Script :
‘This script will move the addresses from static to DHCP on machines it will be executed
Option Explicit
Dim oWSHShell
Dim sNIC, sMan
Dim iCount
Set oWSHShell = WScript.CreateObject(“WScript.Shell”)
‘ First we make the DHCP service to start automatically
oWSHShell.RegWrite “HKLMSYSTEMCurrentControlSetServicesDHCPStart”, 2
‘ Get network card stuff
On Error Resume Next
iCount = 1
Do
sNIC = oWSHShell.RegRead(“HKLMSOFTWAREMicrosoftWindows NT ” & _
“CurrentVersionNetworkCards” & iCount & “ServiceName”)
sMan = oWSHShell.RegRead(“HKLMSOFTWAREMicrosoftWindows NT ” & _
“CurrentVersionNetworkCards” & iCount & “Manufacturer”)
‘ We will ignore 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
Err.Clear
‘ End of Script
Sub SetNIC
Dim iTest
‘ Set the NIC service to use DHCP
sNIC = “HKLMSYSTEMCurrentControlSetServices” & sNIC &”ParametersTCPIP”
iTest = oWSHShell.RegRead(sNIC & “EnableDHCP”)
If iTest = 0 Then
oWSHShell.RegWrite sNIC & “EnableDHCP”, 1, “REG_DWORD”
oWSHShell.RegWrite sNIC & “IPAddress”, “0.0.0.0”, “REG_MULTI_SZ”
oWSHShell.RegWrite sNIC & “SubnetMask”, “0.0.0.0”, “REG_MULTI_SZ”
End If
End Sub
A good resource for time saving scripts can be found here.
Peace.