reset network adapter


Apathy paralysis

I have a VBScript here to "switch" my network adapter (built from a script on the internet).

I was wondering if anyone could help me turn this into a script that would "reset" (disable, then re-enable) my wireless adapter instead of switching it.

'~ Toggle a SPECIFIED NIC on or off
Option Explicit

Const NETWORK_CONNECTIONS = &H31&

Dim objShell, objFolder, objFolderItem, objEnable, objDisable
Dim folder_Object, target_NIC
Dim NIC, clsVerb
Dim str_NIC_Name, strEnable, strDisable
Dim bEnabled, bDisabled

'NIC name goes here VVV
str_NIC_Name = "Wi-Fi"

strEnable = "En&able"
strDisable = "Disa&ble"

' create objects and get items
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)
Set objFolderItem = objFolder.Self
Set folder_Object = objFolderItem.GetFolder

Set target_NIC = Nothing

' look at each NIC and match to the chosen name
For Each NIC In folder_Object.Items
    If LCase(NIC.Name) = LCase(str_NIC_Name) Then
        ' proper NIC is found, get it
        Set target_NIC = NIC
    End If
Next

bEnabled = True
Set objEnable = Nothing
Set objDisable = Nothing

For Each clsVerb In target_NIC.Verbs
    '~ Wscript.Echo clsVerb
    If clsVerb.Name = strEnable Then
        Set objEnable = clsVerb
        bEnabled = False
    End If
    If clsVerb.Name = strDisable Then
        Set objDisable = clsVerb
    End If
Next

If bEnabled Then
    objDisable.DoIt
Else
    objEnable.DoIt
End If

'~ Give the connection time to change
WScript.Sleep 5000
You have

I think it's better to use WMI.

Here is an example script:

Option Explicit

dim ComputerName
dim WMIService, NIC
dim ConnectionName

ComputerName = "."
ConnectionName = "Ethernet"

if not IsElevated then 
    WScript.Echo "Please run this script with administrative rights!"
    WScript.Quit
end if

On Error Resume Next

Set WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2")
Set NIC = WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & ConnectionName & "'").ItemIndex(0)

if NIC is nothing then
    WScript.Echo "NIC not found!"
    WScript.quit
end if

WScript.Echo "NIC Current status: " & iif(NIC.NetEnabled, "Enabled", "Disabled") & vbcrlf

if NIC.NetEnabled then
    WScript.Echo "Disabling NIC..."
    NIC.Disable
    WScript.Sleep 1000
    WScript.Echo "Enabling NIC..."
    NIC.Enable
end if

function iif(cond, truepart, falsepart)
    if cond then iif=truepart else cond=falsepart
end function

function IsElevated()

    On Error Resume Next
    CreateObject("WScript.Shell").RegRead("HKEY_USERS\s-1-5-19\")
    IsElevated = (err.number = 0)

end function

Related


How to reset a network adapter using terminal commands?

Dual life Well, when I turn off the router and turn it on again while running Ubuntu, it doesn't automatically get an IP address: I hit disconnect, but it's still the same as above. It only works when I log out and switch to another session and then go back to

Adapter reset for Android query

in-depth Is it possible to reset the adapter to its original state without making a new query? E.g I have JSONArray, I cut some records to display for selection ListView, but I want to reset the data and display all records again. Is that possible? private JSO

No ad network adapter found

mark I'm trying to implement ads in my app using AdMob and mediated ad networks. But I have the following problem, AdMob cannot find two of the three network adapters. I found some similar posts on StackOverflow, but none of them gave a clear answer to this pr

Change network adapter in KVM

Jake Charman I'm building a server that will be deployed on a KVM host in the near future. I'm using KVM's virt-manager GUI to build a machine on a personal laptop in KVM. First, I left most of the defaults, including creating it's own network with a NAT adapt

No ad network adapter found

mark I'm trying to implement ads in my app using AdMob and mediated ad networks. But I have the following problem, AdMob cannot find two of the three network adapters. I found some similar posts on StackOverflow, but none of them gave a clear answer to this pr

No ad network adapter found

mark I'm trying to implement ads in my app using AdMob and mediated ad networks. But I have the following problem, AdMob cannot find two of the three network adapters. I found some similar posts on StackOverflow, but none of them gave a clear answer to this pr

No ad network adapter found

mark I'm trying to implement ads in my app using AdMob and mediated ad networks. But I have the following problem, AdMob cannot find two of the three network adapters. I found some similar posts on StackOverflow, but none of them gave a clear answer to this pr

Network adapter not recognized at boot

ask you Hello, I am running Ubuntu 16.04 on a fairly clean install. The problem I'm going to explain happens only on Ubuntu , not on Windows 10 or any other OS I've tried. My problem is that I need to unplug and reinstall the USB network adapter every time I t

Change network adapter in KVM

Jake Charman I'm building a server that will be deployed on a KVM host in the near future. I'm using KVM's virt-manager GUI to build a machine on a personal laptop in KVM. First, I left most of the defaults, including creating it's own network with a NAT adapt

No ad network adapter found

mark I'm trying to implement ads in my app using AdMob and mediated ad networks. But I have the following problem, AdMob cannot find two of the three network adapters. I found some similar posts on StackOverflow, but none of them gave a clear answer to this pr

WiFi network adapter disappeared

Oussama Belabbas So I have a problem with my WI-Fi network adapter I'm running a Windows 10 PC After using the PC for a few hours (sometimes only a few minutes) I lost my Wifi connection, tried to reactivate it and the Fi icon didn't respond to any search The

Network adapter not recognized at boot

ask you Hello, I am running Ubuntu 16.04 on a fairly clean install. The problem I'm going to explain happens only on Ubuntu , not on Windows 10 or any other OS I've tried. My problem is that I need to unplug and reinstall the USB network adapter every time I t

No ad network adapter found

mark I'm trying to implement ads in my app using AdMob and mediated ad networks. But I have the following problem, AdMob cannot find two of the three network adapters. I found some similar posts on StackOverflow, but none of them gave a clear answer to this pr

Reset RecylerView without clearing adapter

Barbara: I am trying to manage a RyclerView into my fragment. When I open the app, the fragment is loaded and a list of elements is generated (this is by executing the loadMovie() method). Now that I've added a search button, I want to reload the loadMovie() m

Reset RecylerView without clearing adapter

Barbara: I am trying to manage a RyclerView into my fragment. When I open the app, the fragment is loaded and a list of elements is generated (this is by executing the loadMovie() method). Now that I've added a search button, I want to reload the loadMovie() m

Reset RecylerView without clearing adapter

Barbara: I am trying to manage a RyclerView into my fragment. When I open the app, the fragment is loaded and a list of elements is generated (this is by executing the loadMovie() method). Now that I've added a search button, I want to reload the loadMovie() m

Reset RecylerView without clearing adapter

Barbara: I am trying to manage a RyclerView into my fragment. When I open the app, the fragment is loaded and a list of elements is generated (this is by executing the loadMovie() method). Now that I've added a search button, I want to reload the loadMovie() m

Reset RecylerView without clearing adapter

Barbara: I am trying to manage a RyclerView into my fragment. When I open the app, the fragment is loaded and a list of elements is generated (this is by executing the loadMovie() method). Now that I've added a search button, I want to reload the loadMovie() m

Reset RecylerView without clearing adapter

Barbara: I am trying to manage a RyclerView into my fragment. When I open the app, the fragment is loaded and a list of elements is generated (this is by executing the loadMovie() method). Now that I've added a search button, I want to reload the loadMovie() m

Completely reset the network interface

Paul I have a Raspberry Pi. If it's connected to the network, and the cable has been changed, the IP number has changed, and nothing else, it sometimes stops working. Just restarting will fix the problem. Is there any way to completely reset all network relate

Completely reset the network interface

Paul I have a Raspberry Pi. If it's connected to the network, and the cable has been changed, the IP number has changed, and nothing else, it sometimes stops working. Just restarting will fix the problem. Is there any way to completely reset all network relate

Connect the second network powerline adapter to the network

RXC I bought a network powerline adapter and it works fine. The device I bought came with 2 adapters, one plugged into the router and the other into the computer. I'm wondering if I'm going to buy another network powerline adapter, only one adapter, or if I ne

Connect the second network powerline adapter to the network

RXC I bought a network powerline adapter and it works fine. The device I bought came with 2 adapters, one plugged into the router and the other into the computer. I'm wondering if I'm going to buy another network powerline adapter, only one adapter, or if I ne

HttpURLConnection and using a specific network adapter

Carey: 我想使用Java类HttpURLConnection来连接到(本地网络)上的特定设备。我需要使用特定的网络适配器,因为将要运行我的程序的计算机已安装2个网络适配器。一个适配器位于更广泛的公司网络中,并动态分配了一个IP,而第二个适配器是计算机本地的网络,并且具有静态IP。我要将程序限制在第二个本地网络中。 使用HttpURLConnection的是方便,因为它减轻了我不必解析服务器响应等,并获得直接在我需要的,而不是做类似数据的这个。但是,因为我需要将HTTP请求限制为特定的网络适配器,所以我不能10