Skip to content

Instantly share code, notes, and snippets.

@sukhodolin
Created September 21, 2015 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukhodolin/95a96ef857d555182810 to your computer and use it in GitHub Desktop.
Save sukhodolin/95a96ef857d555182810 to your computer and use it in GitHub Desktop.
Reset Network Adapter if connectivity is lost
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!"
@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