44 Release and Renew IP Addresses

Release and Renew IP Addresses

figs/beginner.gif figs/hack44.gif

Using this handy script, you can release and renew a dynamically assigned IP address with a click of the mouse—well, two clicks, actually.

Troubleshooting DHCP lease problems is frustrating when it involves users' desktop machines, because help desk personnel have to explain to users how to open a command prompt, use the ipconfig command, and interpret the output. It would be nice if there were a way to release and renew a machine's IP address without having to go through such techie steps.

Well, it turns out there is such a way; just use this handy VBScript to release and renew IP addresses assigned through DHCP.

The Code

Type the script into Notepad (with Word Wrap disabled) and save it with a .vbs extension as ReleaseRenew.vbs:

On Error Resume Next

Dim AdapterConfig

Dim RetVal

Set AdapterConfig = GetObject("winmgmts:Win32_NetworkAdapterConfiguration")

'WMI release IP Address for all installed network adapters

RetVal = AdapterConfig.ReleaseDHCPLeaseAll

'if retval = 1 then display success. If 0 then failure

If RetVal = 1 Then

MsgBox "IP Address Release was successful."


MsgBox "DHCP Release failed!"

End If

'WMI renew ip for all network adapters

RetVal = AdapterConfig.RenewDHCPLeaseAll

'if retval = 1 then display success. If 0 then failure

If RetVal = 1 Then

MsgBox "IP Address Renew was successful."


MsgBox "DHCP Renew failed!"

End If

Set AdapterConfig = Nothing

Running the Hack

Copy the script to users' machines and create a shortcut to the script on their desktops. Then, when a user has IP address problems and can't talk to the network, tell her to double-click on the shortcut to release and renew her address, and see if that fixes things. If not, escalate to the next level of troubleshooting!

Rod Trent

     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows