Restart a Network Interface Card NIC programmatically via a Batch command file

Since my network card seems to misbehave recently, I wrote a short script to fix it by restarting the NIC automatically:

@REM ========================================================================
@REM Restarts the NIC if a ping is unsucessful.
@REM
@REM See http://itcookbook.net/blog/enabling-and-disabling-nics-commandline-windows
@REM
@REM To find out NIC number, use "wmic nic get name, index" once and change it.
@REM In this file below, it is "7".
@REM
@REM Written 2011-01-23 by Uwe Keim.
@REM http://www.zeta-uploader.com
@REM ========================================================================

@cls

ping www.google.com | find "Bytes="
if errorlevel 1 goto :mustrestart

@echo ---NOT RESTARTING NIC.
goto :eof

:mustrestart

@echo ---RESTARTING NIC.
wmic path win32_networkadapter where index=7 call disable
wmic path win32_networkadapter where index=7 call enable

:eof

I let Windows Task Scheduler call this script every 10 minutes and have a temporary workaround for my „broken“ NIC.

Important note: If you configure Task Scheduler, be sure to uncheck the option „Run only when a network connection is available“.

Ein Gedanke zu „Restart a Network Interface Card NIC programmatically via a Batch command file

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.