OS:Vista企业
当我在家庭和办公室网络之间切换时,我总是遇到连接到网络的问题。几乎总是我必须在“网络和共享中心”中使用诊断服务,当我使用重置网络适配器选项时问题就解决了。
这需要花费很多时间(3-4分钟),所以我试图找到一个命令或一个PowerShell脚本/ cmdlet,我可以直接使用它来重置网络适配器,每次我必须切换时保存这5分钟网络之间。有什么指针吗?
您可以在PowerShell中使用WMI来完成此任务。假设有一个网络适配器,其设备名称中包含无线,则该系列命令可能如下所示:
$adaptor = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
$adaptor.Disable()
$adaptor.Enable()
请记住,如果您使用Windows Vista运行此功能,则可能需要以管理员身份运行PowerShell。
您还可以使用wmic命令重新启动NIC:
获取接口ID:
C:\>wmic nic get name, index
禁用NIC(InterfaceID:1):
wmic path win32_networkadapter where index=1 call disable
启用NIC(InterfaceID:1):
wmic path win32_networkadapter where index=1 call enable
资料来源:http://www.sysadmit.com/2016/04/windows-reiniciar-red.html
你也可以试试netsh
命令。例:
netsh wlan disconnect && netsh wlan connect [ONE OF YOUR WLAN PROFILES]
您可以使用以下命令获取这些“配置文件”的列表:
netsh wlan show profiles
ipconfig / flushdns
ipconfig /续订
我使用2个cmdlet来刷新连接。您不一定需要重新启动路由器以重新获得强信号(我知道电源循环会清除路由器的内存,但事实确实如此)。
感谢Info,可以使用netsh完成。我写了一个简单的“Repair.bat”脚本:
@echo off
netsh interface set interface "%1" DISABLED
netsh interface set interface "%1" ENABLED
只需使用NIC的名称调用它,重命名为“WLAN”,这样我就没有空格,在cmd中输入“Repair WLAN”即可。我将它放入system32并完成它的任务或者看看如何将它集成到网络上下文菜单中......
Zitrax的回答:
netsh interface set interface "InterfaceName" DISABLED
netsh interface set interface "InterfaceName" ENABLED
是我所寻找的99%。但是,他/她遗漏的一条信息是,这些命令必须以管理员身份运行。以管理员身份运行cmd.exe并键入它们,或将它们存储在批处理文件中,然后右键单击该文件并从上下文菜单中选择“以管理员身份运行”,以管理员身份运行该文件。
您也可以在.BAT或.CMD文件中尝试此操作:
ipconfig /release
ipconfig /renew
arp -d *
nbtstat -R
nbtstat -RR
ipconfig /flushdns
ipconfig /registerdns
这些命令应该与网络适配器的“诊断和修复”相同,但速度更快!
如果这有帮助,请告诉我! JFV
什么对我有用:
netsh interface show interface
显示对我来说是“Ethernet 2”的接口名称然后:
netsh interface set interface "Ethernet 2" DISABLED
netsh interface set interface "Ethernet 2" ENABLED
以下命令对我有用(在Server 2012 R2上):
Restart-NetAdapter -Name "Ethernet 2"
将“Ethernet 2”替换为适配器的名称。
注意:要创建PS脚本:在记事本中创建一个新文档,另存为script.PS1
,插入上面的行并保存。右键单击文件 - >使用PowerShell运行。
有关更多信息,请参阅此technet文章。
请参阅The Scripting Guys,"How Can I Enable or Disable My Network Adapter?"撰写的这篇文章
tl / dr:
Restart-NetAdapter -Name "Your Name Here"
您可以使用获取列表
Get-NetAdapter
Scott的帖子激励我编写一个使用System.Management的非常小的C#/ .Net控制台应用程序。您可以将要重新启动的适配器命名为命令行参数。该代码显示了一些有关处理设备的基础知识,这对其他人也很有用。
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);
}
}
}
}
}
这是我在PowerShell版本5.0.10586.122 Windows 10 Home上使用的内容。这需要以管理员身份运行:
Restart-NetAdapter -Name "ethernet"
要以管理员身份运行它而不必“关闭UAC”或“R-Click->以管理员身份运行”:(这是一次性任务)
Restart-NetAdapter -Name "ethernet"
放入.ps1
文件中.ps1
文件上单击R创建>创建快捷方式)现在,每次运行快捷方式时,只需在UAC屏幕上单击“是”,它将重置您在.ps1
文件中指定的适配器。
要使用PowerShell(WiFi,LAN等)获取可用适配器的名称:
Get-NetAdapter
您还可以使用Microsoft实用程序devcon.exe。
首先,运行devcon listclass net
以查找您的设备ID。
然后在此命令中使用此设备ID:devcon restart PCI\VEN_16*
(使用'*'
通配符以避免需要输入整个ID字符串)。