Solved

batch file to automatically repair LAN connection

Posted on 2009-04-06
6
2,953 Views
Last Modified: 2012-05-06
If anyone is able to help or give advice on where to start I would be most greatfull. At present, for some strange reason, alot of the time on our network outlook goes offline, and occasionally the internet connection will go down as well. At present teh only solution around it is to go to teh computers with that get the problem and view connection settings, and repair. This has been going on for a fair few weeks now, and it is getting tedious repairing it all the time as some of the non-literate computer guys just refuse to learn the steps to repair teh connection.

Anyways.... Is it possible to make a batch that will automatically repair the LAN connection whenever the problem happens, so the computer user can just double clich teh batch icon that I will place on thier desktop.

Any help or advice will br greatly appreciated
0
Comment
Question by:liamrichards
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:anuroopkoka2005
ID: 24075689
Hi

First try to check whether the problem computer is getting the correct DNS server.
try ipconfig /flushdns

the ipconfig /registerdns

once both the commands are executed, see if the problem still persists. or not..

Let me know about this...

I will give u the batch file that the release and renew the LAN connection..
0
 
LVL 4

Accepted Solution

by:
anuroopkoka2005 earned 500 total points
ID: 24075705


Refer to the batch file in the attachment..

U need to rename the extension from .txt to .bat


LAN.txt
0
 
LVL 1

Author Closing Comment

by:liamrichards
ID: 31566945
Thank you very much
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 14

Expert Comment

by:Giovanni Heward
ID: 24760876
Simply right-clicking on the network icon in the taskbar notification area and selecting Repair will perform the ip renewal, among other tasks...
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

Nonetheless, here is a batch file which implements all the tasks... I've added two extra switches to perform the following...
/w - winsock reset (http://support.microsoft.com/kb/811259)
/r - tcp/ip reset (http://support.microsoft.com/kb/299357)


@echo off

cls & echo. & echo NetFix v1.0a by Giovanni Heward (g@utahjrs.com)

echo.

echo [Optional Switches]

echo /w - winsock reset (http://support.microsoft.com/kb/811259)

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

echo.

echo Note: This script may require elevated privileges to operate properly.

echo.

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

) else (

echo err: failed to release ip address

echo err: unable to locate %windir%\system32\ipconfig.exe

)
 

set p=Flushing ARP cache...

if exist %windir%\system32\netsh.exe (

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

) else (

if exist %windir%\system32\arp.exe (

%windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to fush arp cache

echo err: unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe

))
 

set p=Reloading NetBIOS name cache...

if exist %windir%\system32\nbtstat.exe (

echo %p% & title %p% & echo %p% >>%userprofile%\desktop\netfix.log

%windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to reload netbios name cache

echo err: unable to locate %windir%\system32\nbtstat.exe

)
 

set p=Sending NetBIOS name update...

if exist %windir%\system32\nbtstat.exe (

echo %p% & title %p% & echo %p% >>%userprofile%\desktop\netfix.log

%windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to send netbios name update

echo err: unable to locate %windir%\system32\nbtstat.exe

)
 

set p=Flushing DNS cache...

if exist %windir%\system32\ipconfig.exe (

echo %p% & title %p% & echo %p% >>%userprofile%\desktop\netfix.log

%windir%\system32\ipconfig.exe /flushdns 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to flush dns cache

echo err: unable to locate %windir%\system32\ipconfig.exe

)
 

if [%1]==[/w] goto :winsock

if [%1]==[/r] goto :ipreset

goto :cont
 

:ipreset

set p=Resetting TCP/IP...

if exist %windir%\system32\netsh.exe (

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

echo This fix requires a system restart... execute shutdown /a to abort.

if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r

) else (

echo err: failed to reset tcp/ip

echo err: unable to locate %windir%\system32\netsh.exe

)

goto :end
 

:winsock

set p=Resetting Winsock...

if exist %windir%\system32\netsh.exe (

echo %p% & title %p% & echo %p% >>%userprofile%\desktop\netfix.log

%windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to reset winsock

echo err: unable to locate %windir%\system32\netsh.exe

)
 

:cont

set p=Renewing IP address...

if exist %windir%\system32\ipconfig.exe (

echo %p% & title %p% & echo %p% >>%userprofile%\desktop\netfix.log

%windir%\system32\ipconfig.exe /renew 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to renew IP address

echo err: unable to locate %windir%\system32\ipconfig.exe

)
 

set p=Registering DNS name...

if exist %windir%\system32\ipconfig.exe (

echo %p% & title %p% & echo %p% >>%userprofile%\desktop\netfix.log

%windir%\system32\ipconfig.exe /registerdns 1>>%userprofile%\desktop\netfix.log 2>>&1

) else (

echo err: failed to register DNS name

echo err: unable to locate %windir%\system32\ipconfig.exe

)
 

:end

set p= & title NetFix v1.0a by Giovanni Heward (g@utahjrs.com) complete!

echo Network Repair Complete...

pause & exit

Open in new window

netfix.txt
0
 
LVL 14

Expert Comment

by:Giovanni Heward
ID: 24768118
version 2...



@echo off

cls & echo.

echo               __       ___     

echo              /\ \__  /'___\ __

echo   ___      __\ \ ,_\/\ \__//\_\   __  _  

echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 

echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</

echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\

echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/

echo.

echo NetFix v2.0b 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

set p= & title NetFix v2.0b by Giovanni Heward (g@utahjrs.com) complete! & set t= & set d=

echo. & echo Network Repair Complete! & echo ---[Finished: %d% %t%]--->>%userprofile%\desktop\netfix.log

pause & exit

Open in new window

netfix.txt
0
 
LVL 14

Expert Comment

by:Giovanni Heward
ID: 24768394
v 2.0c

- added ipconfig/all info to log file upon completion.
- fixed unset of variables %p% and %t% prior to last usage.



@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

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now