Created
September 21, 2015 00:56
-
-
Save sukhodolin/95a96ef857d555182810 to your computer and use it in GitHub Desktop.
Reset Network Adapter if connectivity is lost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If WScript.Arguments.Count = 2 Then | |
Adapter = WScript.Arguments.Item(0) | |
Action = WScript.Arguments.Item(1) | |
Else | |
Wscript.Echo "Usage: ChangeAdapterState.vbs AdapterName (Enable|Disable)" | |
Wscript.Quit | |
End If | |
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") | |
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter") | |
For Each item in colItems | |
If item.NetConnectionID = Adapter Then | |
Wscript.Echo "Name: " & item.Name | |
If Action = "Disable" Then | |
item.Disable | |
Else | |
item.Enable | |
End If | |
Wscript.Echo Action & ": done!" | |
Wscript.Quit | |
End If | |
Next | |
Wscript.Echo "Not Found!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set Adapter=Test | |
:begin | |
ping -n 1 q >nul 2>&1 | |
echo %ERRORLEVEL% | |
if ERRORLEVEL 1 ( | |
echo Failure Detected! | |
date /t | |
time /t | |
CScript //Nologo ChangeAdapterState.vbs %Adapter% Disable | |
CHOICE /C X /T 5 /D X >nul | |
CScript //Nologo ChangeAdapterState.vbs %Adapter% Enable | |
) else ( | |
echo Passed! | |
) | |
CHOICE /C X /T 3 /D X >nul | |
goto begin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment