Solved

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

Posted on 2009-07-02
7
684 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:Giovanni Heward
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
7 Comments
 
LVL 15

Author Comment

by:Giovanni Heward
ID: 24768575
Of course the main benefit of this script's default operation is creating a log file on the desktop for further analysis...
0
 
LVL 15

Author Comment

by:Giovanni Heward
ID: 24769063
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
 
LVL 15

Author Comment

by:Giovanni Heward
ID: 24769177
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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 21

Accepted Solution

by:
AmazingTech earned 500 total points
ID: 24770979
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
 
LVL 15

Author Closing Comment

by:Giovanni Heward
ID: 31599405
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
 
LVL 15

Author Comment

by:Giovanni Heward
ID: 24832278
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
 
LVL 15

Author Comment

by:Giovanni Heward
ID: 25110144
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question