I would like to enhance my netfix.bat script; I'm unable to determine errorlevels for several "Network Repair" procedures...

Hi,

I've written a batch file, which by default, performs the same functions as simply right-clicking on the network icon in the taskbar notification area and selecting Repair. The process of which is described here http://www.microsoft.com/windowsxp/using/networking/maintain/repair.mspx

This article discusses the command-line equivalents performed by the Repair option... http://support.microsoft.com/kb/289256

I've also added the additional functionality:

/w - winsock reset (http://support.microsoft.com/kb/811259)
/r - tcp/ip reset (http://support.microsoft.com/kb/299357)

However, with some commands I am unable to determine success/failure as the errorlevel appears to returns the same value.  I am only testing with Vista, between non-elevated/elevated privileges.  I feel like I'm missing something...

The problem areas:
1. sending a netbios name update (nbtstat.exe -rr)
2. flushing dns chache (ipconfig.exe /flushdns)
3. renewing dhcp ip lease (ipconfig.exe /renew)
4. registering dns name (ipconfig.exe /registerdns)

@echo off
cls & echo.
echo               __       ___     
echo              /\ \__  /'___\ __
echo   ___      __\ \ ,_\/\ \__//\_\   __  _  
echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 
echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
echo.
echo NetFix v2.0c by Giovanni Heward (g@utahjrs.com)
echo.
echo Performs actions similiar to the network repair option and more!
echo See: http://support.microsoft.com/kb/289256
echo.
echo [Optional Switches]
echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
echo /d   - debug mode
echo.
echo Note: This script requires elevated privileges to operate properly.
echo.
if [%1]==[/?] goto :eof
for /f %%d in ('date/t') do set d=%%d & for /f %%t in ('time/t') do set t=%%t
echo ---[NetFix runtime: %d% %t%]--->>%userprofile%\desktop\netfix.log
 
set p=Releasing IP address
if exist %windir%\system32\ipconfig.exe (
echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /release 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully released IP...
if %errorlevel%==1 echo ERROR: Failed to release IP... check netfix.log
if %errorlevel%==3 echo NOTE: An IP address has not yet been associated with the network endpoint.
) else (echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe)
if [%1]==[/d] pause
 
set p=Flushing ARP cache
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe interface ip delete arpcache 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully flushed ARP cache...
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
) else (
if exist %windir%\system32\arp.exe (
%windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully flushed ARP cache...
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
) else (echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe))
if [%1]==[/d] pause
 
set p=Reloading NetBIOS name cache
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully reloaded NetBIOS name cache...
if %errorlevel%==1 (echo ERROR: Failed to reload NetBIOS name cache... check netfix.log)
) else (
echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe)
if [%1]==[/d] pause
 
set p=Sending NetBIOS name update
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe)
if [%1]==[/d] pause
 
set p=Flushing DNS cache
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /flushdns 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe)
if [%1]==[/d] pause
 
if [%1]==[/w] goto :winsock
if [%1]==[/t] goto :ipreset
goto :cont
 
:ipreset
set p=Resetting TCP/IP
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 (
echo Successfully reset TCP/IP
echo Note: This fix requires a system restart... run "shutdown /a" to abort.
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
)
if %errorlevel%==1 (echo ERROR: Failed to reset tcp/ip... check netfix.log)
) else (echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe)
goto :end
 
:winsock
set p=Resetting Winsock
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 (
echo Successfully reset winsock
echo Note: This fix requires a system restart... run "shutdown /a" to abort.
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
)
if %errorlevel%==1 (echo Failed to reset winsock... check netfix.log)
) else (echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe)
if [%1]==[/d] pause
 
:cont
set p=Renewing IP address
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /renew 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe)
if [%1]==[/d] pause
 
set p=Registering DNS name
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /registerdns 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
 
:end
if exist %windir%\system32\ipconfig.exe (
echo ---[ip configuration]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /all >>%userprofile%\desktop\netfix.log 2>>&1
)
echo. & echo Network Repair Complete! & echo ---[Finished: %d% %t%]--->>%userprofile%\desktop\netfix.log
set p= & title NetFix v2.0b by Giovanni Heward (g@utahjrs.com) complete! & set t= & set d=
pause & exit

Open in new window

netfix.txt
LVL 15
Giovanni HewardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Giovanni HewardAuthor Commented:
Of course the main benefit of this script's default operation is creating a log file on the desktop for further analysis...
0
Giovanni HewardAuthor Commented:
v2.0d

Added /r switch to enable detailed reporting...  Is there an efficient way to detect switches regardless of position?  

For example: netfix /d /r  or netfix /r /d

Rather than.. ?
if [%1]==[/d] goto debug
if [%2]==[/d] goto debug
if [%3]==[/d] goto debug
 
Hmm... something like...
echo %1 %2 %3 %4 %5 %6 %7 %8 %9|find "/r" >nul 2>&1
if %errorlevel%==0 echo /r switch detected

But how to put it into a "routine" ?
set args=%1 %2 %3 %4 %5 %6 %7 %8 %9
call :getswitch /r
if [%p%]==[/r] echo /r switch detected!

call :getswitch /d
if [%p%]==[/d] echo /d switch detected!

set p=
goto :eof

:getswitch
echo %args%|find "%1" >nul 2>&1
if %errorlevel%==0 set p=%1

Look out for v2.0e .. :-)
@echo off
cls & echo.
echo               __       ___     
echo              /\ \__  /'___\ __
echo   ___      __\ \ ,_\/\ \__//\_\   __  _  
echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 
echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
echo.
echo NetFix v2.0d by Giovanni Heward (g@utahjrs.com)
echo.
echo Performs actions similiar to the network repair option and more!
echo See: http://support.microsoft.com/kb/289256
echo.
echo [Optional Switches]
echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
echo /d   - debug mode
echo /r   - detailed reporting
echo.
echo Note: This script requires elevated privileges to operate properly.
echo.
if [%1]==[/?] goto :eof
for /f %%d in ('date/t') do set d=%%d & for /f %%t in ('time/t') do set t=%%t
echo ---[NetFix runtime: %d% %t%]--->>%userprofile%\desktop\netfix.log
 
set p=Releasing IP address
if exist %windir%\system32\ipconfig.exe (
echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /release 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully released IP...
if %errorlevel%==1 echo ERROR: Failed to release IP... check netfix.log
if %errorlevel%==3 echo NOTE: An IP address has not yet been associated with the network endpoint.
) else (echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe)
if [%1]==[/d] pause
 
set p=Flushing ARP cache
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe interface ip delete arpcache 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully flushed ARP cache...
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
) else (
if exist %windir%\system32\arp.exe (
%windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully flushed ARP cache...
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
) else (echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe))
if [%1]==[/d] pause
 
set p=Reloading NetBIOS name cache
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully reloaded NetBIOS name cache...
if %errorlevel%==1 (echo ERROR: Failed to reload NetBIOS name cache... check netfix.log)
) else (
echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe)
if [%1]==[/d] pause
 
set p=Sending NetBIOS name update
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe)
if [%1]==[/d] pause
 
set p=Flushing DNS cache
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /flushdns 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe)
if [%1]==[/d] pause
 
if [%1]==[/w] goto :winsock
if [%1]==[/t] goto :ipreset
goto :cont
 
:ipreset
set p=Resetting TCP/IP
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 (
echo Successfully reset TCP/IP
echo Note: This fix requires a system restart... run "shutdown /a" to abort.
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
)
if %errorlevel%==1 (echo ERROR: Failed to reset tcp/ip... check netfix.log)
) else (echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe)
goto :end
 
:winsock
set p=Resetting Winsock
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 (
echo Successfully reset winsock
echo Note: This fix requires a system restart... run "shutdown /a" to abort.
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
)
if %errorlevel%==1 (echo Failed to reset winsock... check netfix.log)
) else (echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe)
if [%1]==[/d] pause
 
:cont
set p=Renewing IP address
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /renew 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe)
if [%1]==[/d] pause
 
set p=Registering DNS name
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /registerdns 1>>%userprofile%\desktop\netfix.log 2>>&1
if [%1]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
 
:end
if [%1]==[/r] (
if exist %windir%\system32\ipconfig.exe (
echo ---[ip configuration]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /all >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\arp.exe (
echo ---[arp table]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\arp.exe -a >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\ipconfig.exe (
echo ---[dns resolver cache]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /displaydns >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\nbtstat.exe (
echo ---[netbios name tables]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -c >>%userprofile%\desktop\netfix.log 2>>&1
%windir%\system32\nbtstat.exe -n >>%userprofile%\desktop\netfix.log 2>>&1
%windir%\system32\nbtstat.exe -r >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\netstat.exe (
echo ---[routing table ^& enternet/protocol stats]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netstat.exe -r -e -s >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\drivers\etc\hosts (
echo ---[hosts file]--- >>%userprofile%\desktop\netfix.log
type %windir%\system32\drivers\etc\hosts >>%userprofile%\desktop\netfix.log
)
 
if exist %windir%\system32\netstat.exe (
echo. & echo Please wait while I generate a detailed network report...
echo ---[all network connections ^& processes]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netstat.exe -a -b -o -f >>%userprofile%\desktop\netfix.log 2>>&1
)
)
 
echo. & echo Network Repair Complete! & echo ---[Finished: %d% %t%]--->>%userprofile%\desktop\netfix.log
set p= & title NetFix v2.0b by Giovanni Heward (g@utahjrs.com) complete! & set t= & set d=
pause & exit

Open in new window

netfix.txt
0
Giovanni HewardAuthor Commented:
v2.0e

- detects switch options regardless of position (i.e. netfix /d /r  or  netfix /r /d )
- multiple switches supported (i.e. netfix /d /r /t /w )
- added setlocal command and removed unnecessary variable deletion
- added /h help switch (script does not execute)

todo: find a way to determine success/failure on the following:
1. sending a netbios name update (nbtstat.exe -rr)
2. flushing dns chache (ipconfig.exe /flushdns)
3. renewing dhcp ip lease (ipconfig.exe /renew)
4. registering dns name (ipconfig.exe /registerdns)


@echo off
cls & echo.
echo               __       ___     
echo              /\ \__  /'___\ __
echo   ___      __\ \ ,_\/\ \__//\_\   __  _  
echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 
echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
echo.
echo NetFix v2.0e by Giovanni Heward (g@utahjrs.com)
echo.
echo Performs actions similiar to the network repair option and more!
echo See: http://support.microsoft.com/kb/289256
echo.
echo [Optional Switches]
echo /d   - debug mode
echo /r   - detailed reporting
echo /h   - this help screen; no execution.
echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
echo.
echo Note: This script requires elevated privileges to operate properly.
echo.
setlocal
for /f %%d in ('date/t') do set d=%%d & for /f %%t in ('time/t') do set t=%%t
set args=%1 %2 %3 %4 %5 %6 %7 %8 %9
call :getswitch /h
if [%s%]==[/h] (
goto :eof)
 
echo ---[NetFix runtime: %d% %t%]--->>%userprofile%\desktop\netfix.log
 
set p=Releasing IP address
if exist %windir%\system32\ipconfig.exe (
echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /release 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully released IP...
if %errorlevel%==1 echo ERROR: Failed to release IP... check netfix.log
if %errorlevel%==3 echo NOTE: An IP address has not yet been associated with the network endpoint.
) else (echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe)
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Flushing ARP cache
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe interface ip delete arpcache 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully flushed ARP cache...
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
) else (
if exist %windir%\system32\arp.exe (
%windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully flushed ARP cache...
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
) else (echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe))
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Reloading NetBIOS name cache
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 echo Successfully reloaded NetBIOS name cache...
if %errorlevel%==1 (echo ERROR: Failed to reload NetBIOS name cache... check netfix.log)
) else (
echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe)
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Sending NetBIOS name update
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe)
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Flushing DNS cache
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /flushdns 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe)
call :getswitch /d
if [%s%]==[/d] pause
 
call :getswitch /w
if [%s%]==[/w] call :winsock
 
call :getswitch /t
if [%s%]==[/t] (
call :tcpip
) else (
 
 
set p=Renewing IP address
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /renew 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe)
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Registering DNS name
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /registerdns 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
)
 
call :getswitch /r
if [%s%]==[/r] (
if exist %windir%\system32\ipconfig.exe (
echo ---[ip configuration]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /all >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\arp.exe (
echo ---[arp table]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\arp.exe -a >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\ipconfig.exe (
echo ---[dns resolver cache]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\ipconfig.exe /displaydns >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\nbtstat.exe (
echo ---[netbios name tables]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\nbtstat.exe -c >>%userprofile%\desktop\netfix.log 2>>&1
%windir%\system32\nbtstat.exe -n >>%userprofile%\desktop\netfix.log 2>>&1
%windir%\system32\nbtstat.exe -r >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\netstat.exe (
echo ---[routing table ^& enternet/protocol stats]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netstat.exe -r -e -s >>%userprofile%\desktop\netfix.log 2>>&1
)
 
if exist %windir%\system32\drivers\etc\hosts (
echo ---[hosts file]--- >>%userprofile%\desktop\netfix.log
type %windir%\system32\drivers\etc\hosts >>%userprofile%\desktop\netfix.log
)
 
if exist %windir%\system32\netstat.exe (
echo. & echo Please wait while I generate a detailed network report...
echo ---[all network connections ^& processes]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netstat.exe -a -b -o -f >>%userprofile%\desktop\netfix.log 2>>&1
)
)
 
echo. & echo Network Repair Complete! & echo ---[Finished: %d% %t%]--->>%userprofile%\desktop\netfix.log
title NetFix v2.0b by Giovanni Heward (g@utahjrs.com) complete!
pause & exit
goto :eof
 
:getswitch
if exist %windir%\system32\find.exe (
echo %args%|find "%1" >nul 2>&1
if %errorlevel%==0 set s=%1
) else (
echo ERROR: Unable to detect switch options - unable to locate %windir%\system32\find.exe)
)
goto :eof
 
:tcpip
set p=Resetting TCP/IP
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 (
echo Successfully reset TCP/IP
echo Note: This fix requires a system restart... run "shutdown /a" to abort.
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
)
if %errorlevel%==1 (echo ERROR: Failed to reset tcp/ip... check netfix.log)
) else (echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe)
goto :eof
 
:winsock
set p=Resetting Winsock
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
%windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1
call :getswitch /d
if [%s%]==[/d] echo errorlevel: %errorlevel%
if %errorlevel%==0 (
echo Successfully reset winsock
echo Note: This fix requires a system restart... run "shutdown /a" to abort.
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
)
if %errorlevel%==1 (echo Failed to reset winsock... check netfix.log)
) else (echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe)
call :getswitch /d
if [%s%]==[/d] pause
set s=

Open in new window

netfix.txt
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

AmazingTechCommented:
This

set args=%1 %2 %3 %4 %5 %6 %7 %8 %9

can be replaced with

set args=%*

Your finds should include a /i so it will ignore case. As it is right now /d and /D are different.

Try it like this.
@echo off
cls & echo.
echo       __       ___     
echo      /\ \__  /'___\ __
echo   ___      __\ \ ,_\/\ \__//\_\   __  _  
echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 
echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
echo.
echo NetFix v2.0e by Giovanni Heward (g@utahjrs.com)
echo.
echo Performs actions similiar to the network repair option and more!
echo See: http://support.microsoft.com/kb/289256
echo.
echo [Optional Switches]
echo /d   - debug mode
echo /r   - detailed reporting
echo /h   - this help screen; no execution.
echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
echo.
echo Note: This script requires elevated privileges to operate properly.
echo.
setlocal
for /f %%d in ('date/t') do set d=%%d & for /f %%t in ('time/t') do set t=%%t
set args=%*
call :getswitch /h
if [%s%]==[/h] goto :eof
 
echo ---[NetFix runtime: %d% %t%]--->>%userprofile%\desktop\netfix.log
 
set p=Releasing IP address
if exist %windir%\system32\ipconfig.exe (
    echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\ipconfig.exe /release 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 echo Successfully released IP...
    if %errorlevel%==1 echo ERROR: Failed to release IP... check netfix.log
    if %errorlevel%==3 echo NOTE: An IP address has not yet been associated with the network endpoint.
) else (
    echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Flushing ARP cache
if exist %windir%\system32\netsh.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\netsh.exe interface ip delete arpcache 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 echo Successfully flushed ARP cache...
    if %errorlevel%==1 echo ERROR: Failed to flush ARP cache... check netfix.log
) else (
    if exist %windir%\system32\arp.exe (
         %windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1
         call :getswitch /d
         if [%s%]==[/d] echo errorlevel: %errorlevel%
         if %errorlevel%==0 echo Successfully flushed ARP cache...
         if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
    ) else (
         echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe
    )
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
set p=Reloading NetBIOS name cache
if exist %windir%\system32\nbtstat.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 echo Successfully reloaded NetBIOS name cache...
    if %errorlevel%==1 echo ERROR: Failed to reload NetBIOS name cache... check netfix.log
) else (
    echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Sending NetBIOS name update
if exist %windir%\system32\nbtstat.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (
    echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Flushing DNS cache
if exist %windir%\system32\ipconfig.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\ipconfig.exe /flushdns 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (
    echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
call :getswitch /w
if [%s%]==[/w] call :winsock
 
call :getswitch /t
if [%s%]==[/t] (
    call :tcpip
) else (
    set p=Renewing IP address
    if exist %windir%\system32\ipconfig.exe (
        echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
        %windir%\system32\ipconfig.exe /renew 1>>%userprofile%\desktop\netfix.log 2>>&1
        call :getswitch /d
        if [%s%]==[/d] echo errorlevel: %errorlevel%
    ) else (
        echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe
    )
 
    call :getswitch /d
    if [%s%]==[/d] pause
 
    set p=Registering DNS name
    if exist %windir%\system32\ipconfig.exe (
        echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
        %windir%\system32\ipconfig.exe /registerdns 1>>%userprofile%\desktop\netfix.log 2>>&1
        call :getswitch /d
        if [%s%]==[/d] echo errorlevel: %errorlevel%
    ) else (
        echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
    )
 
    call :getswitch /r
    if [%s%]==[/r] (
        if exist %windir%\system32\ipconfig.exe (
            echo ---[ip configuration]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\ipconfig.exe /all >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
        if exist %windir%\system32\arp.exe (
            echo ---[arp table]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\arp.exe -a >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
        if exist %windir%\system32\ipconfig.exe (
            echo ---[dns resolver cache]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\ipconfig.exe /displaydns >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
 
        if exist %windir%\system32\nbtstat.exe (
            echo ---[netbios name tables]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\nbtstat.exe -c >>%userprofile%\desktop\netfix.log 2>>&1
            %windir%\system32\nbtstat.exe -n >>%userprofile%\desktop\netfix.log 2>>&1
            %windir%\system32\nbtstat.exe -r >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
 
        if exist %windir%\system32\netstat.exe (
            echo ---[routing table ^& enternet/protocol stats]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\netstat.exe -r -e -s >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
        if exist %windir%\system32\drivers\etc\hosts (
            echo ---[hosts file]--- >>%userprofile%\desktop\netfix.log
            type %windir%\system32\drivers\etc\hosts >>%userprofile%\desktop\netfix.log
        )
 
        if exist %windir%\system32\netstat.exe (
            echo. & echo Please wait while I generate a detailed network report...
            echo ---[all network connections ^& processes]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\netstat.exe -a -b -o -f >>%userprofile%\desktop\netfix.log 2>>&1
        )
    )
)
 
echo. & echo Network Repair Complete! & echo ---[Finished: %d% %t%]--->>%userprofile%\desktop\netfix.log
title NetFix v2.0b by Giovanni Heward (g@utahjrs.com) complete!
pause & exit
goto :eof
 
:getswitch
if exist %windir%\system32\find.exe (
    echo %args%|find /i "%1" >nul 2>&1
    if %errorlevel%==0 set s=%1
) else (
    echo ERROR: Unable to detect switch options - unable to locate %windir%\system32\find.exe)
)
goto :eof
 
:tcpip
set p=Resetting TCP/IP
if exist %windir%\system32\netsh.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>%userprofile%\desktop\netfix.log 2>>&1
 
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 (
        echo Successfully reset TCP/IP
        echo Note: This fix requires a system restart... run "shutdown /a" to abort.
        if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
    ) else (
        echo ERROR: Failed to reset tcp/ip... check netfix.log
    )
) else (
    echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe
)
goto :eof
 
:winsock
set p=Resetting Winsock
if exist %windir%\system32\netsh.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 (
        echo Successfully reset winsock
        echo Note: This fix requires a system restart... run "shutdown /a" to abort.
        if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
    ) else (
        echo Failed to reset winsock... check netfix.log
    )
) else (
    echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
set s=

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Giovanni HewardAuthor Commented:
Assisted with efficiently detecting switches, regardless of case.  Still need answers to detecting success/failure for the following problem areas:

1. sending a netbios name update (nbtstat.exe -rr)
2. flushing dns chache (ipconfig.exe /flushdns)
3. renewing dhcp ip lease (ipconfig.exe /renew)
4. registering dns name (ipconfig.exe /registerdns)
0
Giovanni HewardAuthor Commented:
Latest...

@echo off
setlocal & set args=%* & set v=v2.0f
cls & echo.
echo               __       ___     
echo              /\ \__  /'___\ __
echo   ___      __\ \ ,_\/\ \__//\_\   __  _  
echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 
echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
echo.
echo NetFix %v% by Giovanni Heward (g@utahjrs.com)
echo.
echo Performs actions similiar to the network repair option and more!
echo See: http://support.microsoft.com/kb/289256
echo.
echo [Optional Switches]
echo /d   - debug mode
echo /r   - detailed reporting
echo /h   - this help screen; no execution.
echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
echo.
echo Note: This script requires elevated privileges to operate properly.
echo.
 
call :getswitch /h
if [%s%]==[/h] goto :eof
 
echo ---[NetFix runtime: %date% %time%]--->>%userprofile%\desktop\netfix.log
 
set p=Releasing IP address
if exist %windir%\system32\ipconfig.exe (
    echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\ipconfig.exe /release 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 echo Successfully released IP...
    if %errorlevel%==1 echo ERROR: Failed to release IP... check netfix.log
    if %errorlevel%==3 echo NOTE: An IP address has not yet been associated with the network endpoint.
) else (
    echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Flushing ARP cache
if exist %windir%\system32\netsh.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\netsh.exe interface ip delete arpcache 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 echo Successfully flushed ARP cache...
    if %errorlevel%==1 echo ERROR: Failed to flush ARP cache... check netfix.log
) else (
    if exist %windir%\system32\arp.exe (
         %windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1
         call :getswitch /d
         if [%s%]==[/d] echo errorlevel: %errorlevel%
         if %errorlevel%==0 echo Successfully flushed ARP cache...
         if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log)
    ) else (
         echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe
    )
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
set p=Reloading NetBIOS name cache
if exist %windir%\system32\nbtstat.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 echo Successfully reloaded NetBIOS name cache...
    if %errorlevel%==1 echo ERROR: Failed to reload NetBIOS name cache... check netfix.log
) else (
    echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Sending NetBIOS name update
if exist %windir%\system32\nbtstat.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (
    echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
 
set p=Flushing DNS cache
if exist %windir%\system32\ipconfig.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\ipconfig.exe /flushdns >>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
) else (
    echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
 
call :getswitch /w
if [%s%]==[/w] call :winsock
 
call :getswitch /t
if [%s%]==[/t] (
    call :tcpip
) else (
    set p=Renewing IP address
    if exist %windir%\system32\ipconfig.exe (
        echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
        %windir%\system32\ipconfig.exe /renew >>%userprofile%\desktop\netfix.log 2>>&1
        call :getswitch /d
        if [%s%]==[/d] echo errorlevel: %errorlevel%
    ) else (
        echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe
    )
 
    call :getswitch /d
    if [%s%]==[/d] pause
 
    set p=Registering DNS name
    if exist %windir%\system32\ipconfig.exe (
        echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
        %windir%\system32\ipconfig.exe /registerdns >>%userprofile%\desktop\netfix.log 2>>&1
        call :getswitch /d
        if [%s%]==[/d] echo errorlevel: %errorlevel%
    ) else (
        echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
    )
 
    call :getswitch /r
    if [%s%]==[/r] (
        if exist %windir%\system32\ipconfig.exe (
            echo ---[ip configuration]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\ipconfig.exe /all >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
        if exist %windir%\system32\arp.exe (
            echo ---[arp table]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\arp.exe -a 1>>%userprofile%\desktop\netfix.log 2>>&1
        )
 
        if exist %windir%\system32\ipconfig.exe (
            echo ---[dns resolver cache]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\ipconfig.exe /displaydns >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
 
        if exist %windir%\system32\nbtstat.exe (
            echo ---[netbios name tables]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\nbtstat.exe -c >>%userprofile%\desktop\netfix.log 2>>&1
            %windir%\system32\nbtstat.exe -n >>%userprofile%\desktop\netfix.log 2>>&1
            %windir%\system32\nbtstat.exe -r >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
 
        if exist %windir%\system32\netstat.exe (
            echo ---[routing table ^& enternet/protocol stats]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\netstat.exe -r -e -s >>%userprofile%\desktop\netfix.log 2>>&1
        )
 
        if exist %windir%\system32\drivers\etc\hosts (
            echo ---[hosts file]--- >>%userprofile%\desktop\netfix.log
            type %windir%\system32\drivers\etc\hosts >>%userprofile%\desktop\netfix.log
        )
 
        if exist %windir%\system32\netstat.exe (
            echo. & echo Please wait while I generate a detailed network report...
            echo ---[all network connections ^& processes]--- >>%userprofile%\desktop\netfix.log
            %windir%\system32\netstat.exe -a -b -o -f >>%userprofile%\desktop\netfix.log 2>>&1
        )
    )
)
 
echo. & echo Network Repair Complete! & echo ---[Finished: %date% %time%]--->>%userprofile%\desktop\netfix.log
title NetFix %v% by Giovanni Heward (g@utahjrs.com) complete!
pause & exit
goto :eof
 
:getswitch
echo %args%|find.exe /i "%1" >nul 2>&1
if %errorlevel%==0 set s=%1
goto :eof
 
:tcpip
set p=Resetting TCP/IP
if exist %windir%\system32\netsh.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>%userprofile%\desktop\netfix.log 2>>&1
 
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 (
        echo Successfully reset TCP/IP
        echo Note: This fix requires a system restart... run "shutdown /a" to abort.
        if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
    ) else (
        echo ERROR: Failed to reset tcp/ip... check netfix.log
    )
) else (
    echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe
)
goto :eof
 
:winsock
set p=Resetting Winsock
if exist %windir%\system32\netsh.exe (
    echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log
    %windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1
    call :getswitch /d
    if [%s%]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 (
        echo Successfully reset winsock
        echo Note: This fix requires a system restart... run "shutdown /a" to abort.
        if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
    ) else (
        echo Failed to reset winsock... check netfix.log
    )
) else (
    echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe
)
 
call :getswitch /d
if [%s%]==[/d] pause
set s=

Open in new window

netfix.txt
0
Giovanni HewardAuthor Commented:
Final... for now. v3.0

@echo off
setlocal enabledelayedexpansion&set args=%*&set v=v3.0&set log=%userprofile%\desktop\netfix.log
cls & echo.
echo               __       ___
echo              /\ \__  /'___\ __
echo   ___      __\ \ ,_\/\ \__//\_\   __  _
echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\
echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
echo.
echo NetFix %v% by Giovanni Heward (giovanni@hewardassociates.com)
echo.
echo Performs actions similiar to the network repair option and more!
echo See: http://support.microsoft.com/kb/289256
echo.
echo [Optional Switches]
echo /d   - debug mode
echo /r   - detailed reporting
echo /h   - this help screen; no execution.
echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
echo.
echo Note: This script requires elevated privileges to operate properly. (Vista/7)
echo.
 
call :getswitch /h
if [!s!]==[/h] goto :eof
 
echo ---[NetFix runtime: %date% %time%]--->!log!
 
set p=Releasing IP address
if exist %windir%\system32\ipconfig.exe (
    echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\ipconfig.exe /release 1>>!log! 2>>&1
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
    if [%errorlevel%]==[0] echo Successfully released IP...
    if [%errorlevel%]==[1] echo ERROR: Failed to release IP... check netfix.log
    if [%errorlevel%]==[3] echo NOTE: An IP address has not yet been associated with the network endpoint.
) else (
    echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe
)
 
call :getswitch /d
if [!s!]==[/d] pause
 
 
set p=Flushing ARP cache
if exist %windir%\system32\netsh.exe (
    echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\netsh.exe interface ip delete arpcache 1>>!log! 2>>&1
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
    if [%errorlevel%]==[0] echo Successfully flushed ARP cache...
    if [%errorlevel%]==[1] echo ERROR: Failed to flush ARP cache... check netfix.log
) else (
    if exist %windir%\system32\arp.exe (
         %windir%\system32\arp.exe -d * 1>>!log! 2>>&1
         call :getswitch /d
         if [!s!]==[/d] echo errorlevel: %errorlevel%
         if [%errorlevel%]==[0] echo Successfully flushed ARP cache...
         if [%errorlevel%]==[1] (echo ERROR: Failed to flush ARP cache... check netfix.log)
    ) else (
         echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe
    )
)
 
call :getswitch /d
if [!s!]==[/d] pause
 
set p=Reloading NetBIOS name cache
if exist %windir%\system32\nbtstat.exe (
    echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\nbtstat.exe -R 1>>!log! 2>>&1
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
    if [%errorlevel%]==[0] echo Successfully reloaded NetBIOS name cache...
    if [%errorlevel%]==[1] echo ERROR: Failed to reload NetBIOS name cache... check netfix.log
) else (
    echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe
)
 
call :getswitch /d
if [!s!]==[/d] pause
 
set p=Sending NetBIOS name update
if exist %windir%\system32\nbtstat.exe (
    echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\nbtstat.exe -RR 1>>!log! 2>>&1
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
) else (
    echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe
)
 
call :getswitch /d
if [!s!]==[/d] pause
 
set p=Flushing DNS cache
if exist %windir%\system32\ipconfig.exe (
    echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\ipconfig.exe /flushdns >>!log! 2>>&1
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
) else (
    echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe
)
 
call :getswitch /d
if [!s!]==[/d] pause
 
call :getswitch /w
if [!s!]==[/w] call :winsock
 
call :getswitch /t
if [!s!]==[/t] (
    call :tcpip
) else (
    set p=Renewing IP address
    if exist %windir%\system32\ipconfig.exe (
        echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
        %windir%\system32\ipconfig.exe /renew >>!log! 2>>&1
        call :getswitch /d
        if [!s!]==[/d] echo errorlevel: %errorlevel%
    ) else (
        echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe
    )
 
    call :getswitch /d
    if [!s!]==[/d] pause
 
    set p=Registering DNS name
    if exist %windir%\system32\ipconfig.exe (
        echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
        %windir%\system32\ipconfig.exe /registerdns >>!log! 2>>&1
        call :getswitch /d
        if [!s!]==[/d] echo errorlevel: %errorlevel%
    ) else (
        echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
    )
 
    call :getswitch /r
    if [!s!]==[/r] (
        if exist %windir%\system32\ipconfig.exe (
            echo ---[ip configuration]--- >>!log!
            %windir%\system32\ipconfig.exe /all >>!log! 2>>&1
        )
 
        if exist %windir%\system32\arp.exe (
            echo ---[arp table]--- >>!log!
            %windir%\system32\arp.exe -a 1>>!log! 2>>&1
        )
 
        if exist %windir%\system32\ipconfig.exe (
            echo ---[dns resolver cache]--- >>!log!
            %windir%\system32\ipconfig.exe /displaydns >>!log! 2>>&1
        )
 
 
        if exist %windir%\system32\nbtstat.exe (
            echo ---[netbios name tables]--- >>!log!
            %windir%\system32\nbtstat.exe -c >>!log! 2>>&1
            %windir%\system32\nbtstat.exe -n >>!log! 2>>&1
            %windir%\system32\nbtstat.exe -r >>!log! 2>>&1
        )
 
 
        if exist %windir%\system32\netstat.exe (
            echo ---[routing table ^& ethernet/protocol stats]--- >>!log!
            %windir%\system32\netstat.exe -r -e -s >>!log! 2>>&1
        )
 
        if exist %windir%\system32\drivers\etc\hosts (
            echo ---[hosts file]--- >>!log!
            type %windir%\system32\drivers\etc\hosts >>!log!
        )
 
        if exist %windir%\system32\netstat.exe (
            echo. & echo Please wait while I generate a detailed network report...
            echo ---[all network connections ^& processes]--- >>!log!
            %windir%\system32\netstat.exe -a -b -o -f >>!log! 2>>&1
        )
    )
)
 
echo. & echo Network Repair Complete! & echo ---[Finished: %date% %time%]--->>!log!
title NetFix %v% by Giovanni Heward (giovanni@hewardassociates.com) complete
goto :eof
 
:getswitch
echo !args!|find.exe /i "%1" >nul 2>&1
if %errorlevel%==0 set s=%1
goto :eof
 
:tcpip
set p=Resetting TCP/IP
if exist %windir%\system32\netsh.exe (
    echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>!log! 2>>&1
 
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 (
        echo Successfully reset TCP/IP
        echo Note: This fix requires a system restart... run "shutdown /a" to abort.
        if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
    ) else (
        echo ERROR: Failed to reset tcp/ip... check netfix.log
    )
) else (
    echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe
)
goto :eof
 
:winsock
set p=Resetting Winsock
if exist %windir%\system32\netsh.exe (
    echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
    %windir%\system32\netsh.exe winsock reset 1>>!log! 2>>&1
    call :getswitch /d
    if [!s!]==[/d] echo errorlevel: %errorlevel%
    if %errorlevel%==0 (
        echo Successfully reset winsock
        echo Note: This fix requires a system restart... run "shutdown /a" to abort.
        if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
    ) else (
        echo Failed to reset winsock... check netfix.log
    )
) else (
    echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe
)
 
call :getswitch /d
if [!s!]==[/d] pause

Open in new window

netfix.txt
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.