Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 741 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Command/Powershell script to reset a network adapter

#1
OS: Vista enterprise

When i switch between my home and office network, i always face issues with getting connected to the network. Almost always I have to use the diagnostic service in 'Network and sharing center' and the problem gets solved when i use the reset network adapter option.

This takes a lot of time (3-4 min) and so i was trying to find either a command or a powershell script/cmdlet which i can use directly to reset the network adapter and save myself these 5 mins every time i have to switch between the networks. Any pointers?
Reply

#2
You can also try this in a .BAT or .CMD file:

ipconfig /release
ipconfig /renew
arp -d *
nbtstat -R
nbtstat -RR
ipconfig /flushdns
ipconfig /registerdns

These commands should do the same things as the 'Diagnose and Repair' for the network adapter, but is WAY faster!

Let me know if this helps!
JFV
Reply

#3
You can use WMI from within PowerShell to accomplish this. Assuming there is a network adapter who's device name has *Wireless* in it, the series of commands might look something like the following:

$adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
$adaptor.Disable()
$adaptor.Enable()

Remember, if you're running this with Window's Vista, you may need to run the PowerShell *as Administrator*.
Reply

#4
You can also use the Microsoft utility [devcon.exe][1].

First, run `devcon listclass net` to find your Device ID.

Then use this device ID in this command: `devcon restart PCI\VEN_16*` (using the `'*'` wildcard to avoid needing to enter the entire ID string).

[1]:

[To see links please register here]

Reply

#5
The post of Scott inspired me to write a very small C# / .Net console application, that uses System.Management. You can name the adapter, that you want to restart, as a command line parameter. The code shows some basics about handling devices, that could be useful for others too.

using System;
using System.Management;

namespace ResetNetworkAdapter
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("ResetNetworkAdapter [adapter name]");
Console.WriteLine("disables and re-enables (restarts) network adapters containing [adapter name] in their name");
return;
}

// commandline parameter is a string to be contained in the searched network adapter name
string AdapterNameLike = args[0];

// get network adapter node
SelectQuery query = new SelectQuery("Win32_NetworkAdapter");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection adapters = searcher.Get();

// enumerate all network adapters
foreach (ManagementObject adapter in adapters)
{
// find the matching adapter
string Name = (string)adapter.Properties["Name"].Value;
if (Name.ToLower().Contains(AdapterNameLike.ToLower()))
{
// disable and re-enable the adapter
adapter.InvokeMethod("Disable", null);
adapter.InvokeMethod("Enable", null);
}
}
}
}
}
Reply

#6
You could also try `netsh` commands. Example:

netsh wlan disconnect && netsh wlan connect [ONE OF YOUR WLAN PROFILES]

You can get a list of those "profiles", using:

netsh wlan show profiles
Reply

#7
What worked for me:

netsh interface show interface

to show the interface name which for me was "Ethernet 2" and then:

netsh interface set interface "Ethernet 2" DISABLED
netsh interface set interface "Ethernet 2" ENABLED
Reply

#8
ipconfig /flushdns

ipconfig /renew


Are the 2 cmdlets I use to refresh my connection. You don't necessarily need to power cycle the router to re-gain a strong signal( I know power cycling clears the router's memory but that's really it).
Reply

#9
Zitrax's answer:

netsh interface set interface "InterfaceName" DISABLED
netsh interface set interface "InterfaceName" ENABLED
was 99% of what I was looking for. The one piece of information that s/he left out, though, was that these commands have to be run as an administrator. Either run cmd.exe as an admin and type them in, or store them in a batch file, and then run that file as admin by right clicking on it and choosing "Run as Administrator" from the context menu.
Reply

#10
This is what I use on PowerShell version 5.0.10586.122 Windows 10 Home. This needs to be run as an administrator:

`Restart-NetAdapter -Name "ethernet"`

To run this as an administrator without having to "Turn off UAC" or "<kbd>R-Click</kbd>-> Run as administrator": (This is a one time task)

- Put the above `Restart-NetAdapter -Name "ethernet"` into a `.ps1` file
- Create a new shortcut (<kbd>R-Click</kbd> on `.ps1` file > Create Shortcut)
- On the Shortcut, <kbd>R-Click</kbd> > Properties > Shortcut > Target > (Append Powershell.exe to precede the Location/filename as shown below.
Also enclose the Location/filename with double quotes("), also shown below.

[![enter image description here][1]][1]

- On the Shortcut, <kbd>R-Click</kbd> > Properties > Shortcut > Advanced > "Run As Administrator"(Check this Check box)


Now every time you run the shortcut, you will need to just click "Yes" on the UAC screen and it will reset the adapter you've specified in the `.ps1` file.

To get the names of the available adapters using PowerShell(WiFi, LAN etc.,):

`Get-NetAdapter`


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through