Release all DHCP IP addresses using WQL (VBScript)
This code can be found in
Chapter 12 of Windows XP Cookbook
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the VBScript code from this site.
' From the book "Windows XP Cookbook"
' ISBN: 0596007256
' This code performs a query for all DHCP enabled IP addresses and releases
' them. Use this instead of the other example if you want to tailor the
' query to return a subset of connections. Modify the WQL statement based
' on your criteria.
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colNetworkAdapters = objWMI.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where DHCPEnabled = True")
for each objNetworkConfig in colNetworkAdapters
intRC = objNetworkConfig.ReleaseDHCPLease()
if intRC = 0 then
WScript.Echo "Released IP address for " & objNetworkConfig.Description
elseif intRC = 1 then
WScript.Echo "You must reboot to release the IP address for " & _
objNetworkConfig.Description
else
WScript.Echo "There was an error releasing the IP address for " & _
objNetworkConfig.Description & ": " & intRC
end if
next
|
This code has been viewed 1413 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|