FixDHCP script

This is a Visual Basic script that tries to fix DHCP problems under Microsoft Windows by releasing and renewing DHCP leases, and then displaying the results. Copy, paste, and save these lines into a file named FixDHCP.vbs. Double-click the file to run it with any SSO Login. ' FIXDHCP VERSION 0.2.1 BY JOHN NAVAS ' RELEASE AND RENEW ALL DHCP ADDRESSES, THEN DISPLAY IPCONFIG /ALL

On Error Resume Next

' FORCE USE OF CSCRIPT INSTEAD OF WSCRIPT UseCscript Set objStdOut = WScript.StdOut

Dim WshShell, oExec Set WshShell = CreateObject("WScript.Shell")

' DISPLAY OS AND VERSION Set oExec = WshShell.Exec("%COMSPEC% /C VER") output = "" Do While Not oExec.StdOut.AtEndOfStream output = output & oExec.StdOut.ReadAll WScript.Sleep 100 Loop objStdOut.WriteLine output

' PROCESS ALL IP ADAPTERS Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( "SELECT *" _   & " FROM Win32_NetworkAdapterConfiguration" _    & " Where IPEnabled = True",,48) For Each objItem in colItems DoAdapter objItem Next

Cmd = "IPCONFIG /ALL" Set oExec = WshShell.Exec(Cmd) output = "" Do While Not oExec.StdOut.AtEndOfStream output = output & oExec.StdOut.ReadAll WScript.Sleep 100 Loop objStdOut.WriteLine Cmd & output

objStdOut.WriteLine "This screen may be copied to clipboard" _ & " for pasting into other Windows:" objStdOut.WriteLine "Click System Menu icon, Edit -> Mark," _ & " select text, and Edit -> Copy." objStdOut.WriteBlankLines 1 objStdOut.Write "Press [Enter] to close..." objStdOut.Close Wscript.StdIn.ReadLine

' IF WSCRIPT, SWITCH TO CSCRIPT Sub UseCscript pcengine = LCase(Mid(WScript.FullName, _ InstrRev(WScript.FullName,"\")+1)) If Not pcengine="cscript.exe" Then Set WshShell = CreateObject("WScript.Shell") WshShell.Run "CSCRIPT.EXE """ & WScript.ScriptFullName & """" WScript.Quit End If End Sub

' PROCESS IP ADAPTER Sub DoAdapter(objItem) objStdOut.WriteLine objItem.Description objStdOut.WriteLine "MACAddress: " & objItem.MACAddress

objStdOut.WriteLine "DHCPEnabled: " & objItem.DHCPEnabled If objItem.DHCPEnabled Then

objStdOut.Write "Release IP Address..." rtrn = objItem.ReleaseDHCPLease if rtrn = 0 Then objStdOut.WriteLine "success." Else objStdOut.WriteLine "failure (" & rtrn & ")!" End If

objStdOut.Write "Renew IP Address..." rtrn = objItem.RenewDHCPLease if rtrn = 0 Then objStdOut.WriteLine "success." Else objStdOut.WriteLine "failure (" & rtrn & ")!" End If

objStdOut.WriteLine "DHCPServer: " & objItem.DHCPServer objStdOut.WriteLine "DHCPLeaseExpires: " _ & objItem.DHCPLeaseExpires objStdOut.WriteLine "DHCPLeaseObtained: " _ & objItem.DHCPLeaseObtained End If

For Each strIPAddress in objItem.IPAddress objStdOut.WriteLine "IP Address: " & strIPAddress Next objStdOut.WriteLine "IPConnectionMetric: " _ & objItem.IPConnectionMetric

objStdOut.WriteBlankLines 1 End Sub