可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Does anyone know exactly what Windows XP does when you click "Repair" on a network connection? I'd like to do the same programmatically or from a command line.
I did a Google search and found this article, which has a good explanation, but I don't think it's complete. I can reliably reproduce a condition where I lose network connectivity and clicking the Repair button fixes the problem, but running the commands in that article does not.
回答1:
Thanks, guys, I think I figured it out. The steps in the MS KB article posted by lpfavreau are almost complete. That's what I tried and it didn't work. However, if I do ipconfig /release
first then it seems to work. I suspect that the "Repair" button does that without it being explicitly documented. For my particular case I also had to clear the routes ("route -f"). So, the commands I ended up running in the end are:
route -f
ipconfig /release
ipconfig /renew
arp -d *
nbtstat -R
nbtstat -RR
ipconfig /flushdns
ipconfig /registerdns
I also found some C code to call the actual "Repair Connections" functionality, though I haven't tested it - see last post here.
回答2:
Seems there's a few more things it does:
- Dynamic Host Configuration Protocol (DHCP) lease is renewed: ipconfig /renew
- Address Resolution Protocol (ARP) cache is flushed: arp -d
- Reload of the NetBIOS name cache: nbtstat -R
- NetBIOS name update is sent: nbtstat -RR
- Domain Name System (DNS) cache is flushed: ipconfig /flushdns
- DNS name registration: ipconfig /registerdns
One thing though, if you have a connection that breaks so often you need to programmatically repair your network, this might not be the solution you are looking for.
回答3:
There is a command to do it from the command line.
Quoting http://en.kioskea.net/faq/sujet-848-windows-xp-repairing-the-network-connection-using-command-line:
Under Windows XP there is a small feature allowing you to repair a network connection. Go to the Network Connections options in Control panel (Control Panel / Network Connections), right click on the network connection you want and choose the repair option.
It is possible to run the same command by using the Netsh utility, within the following command line:
netsh int ip reset c:\network-connection.log
c:\network-connection.log represents the address of the file in which the reporting will be stored
The netsh int ip ...command allows you to reset the TCP/IP.
With Windows XP Service Pack 2, you can use:
netsh winsock reset catalog
Resetting the socket which manages the TCP/IP. This can be used to handle network problems (browser problem, IP address related problems, etc ...)
回答4:
In the case of a wireless connection, it also disables and re-enables the network adapter. I suspect something like that is what's missing from the article.
回答5:
Apart from the points listed by lpfavreau and Evgeny, "Repair" network connection also does the following.
- Reset the networking device MAC (and probably PHY). This causes the device to re-initiate all its local data-structures, clearing any error conditions it might have got stuck in.
- Clear the Rx/Tx packet queues in the device-driver and the network interface, flushing it of any older queued packets.
回答6:
I experience wifi connection, dropped from time to time on my XP box, without any apparent reason, and the only way to fix this is to right click on the wifi connection icon on systray and repair.
To get this done from command line, I follow the steps on this article and it works for me: http://wlanbook.com/enable-disable-wireless-card-command-line/
回答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
回答8:
回答9:
It's just done with 1 api call !
see on Win32 api forum news://comp.os.ms-windows.programmer.win32
where the code had been given (C)
回答10:
The closest thing I could find on this was.
http://msdn.microsoft.com/en-us/library/ff358632(v=vs.85).aspx
回答11:
This has worked for me.
Create a batch file ( I called mine netrepair.bat) and place it in a directory where you have execute permissions. Use notepad to create the file.
type the following lines in the file
ipconfig /renew
arp -d *
nbtstat -R
nbtstat -RR
ipconfig /flushdns
ipconfig /registerdns
then save and close.
Open a cmd terminal as administrator, navigate to the folder on which netrepair.bat is saved and then type
netrepair.bat
at the command line.
That's it.
Refer to http://support.microsoft.com/kb/289256 for explanations of what the commands do
回答12:
Here is a Task Manager XML file (import it into Task Manager) that will execute a netsh interface set interface "Ethernet" DISABLED" followed by an "ENABLED", 5 seconds after wake up.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2015-01-15T10:19:28.1634612</Date>
<Author>MACHINE\user</Author>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='Microsoft-Windows-Power-Troubleshooter'] and EventID=1]]</Select></Query></QueryList></Subscription>
<Delay>PT5S</Delay>
</EventTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>true</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Windows\System32\netsh.exe</Command>
<Arguments>interface set interface "Ethernet" DISABLED</Arguments>
</Exec>
<Exec>
<Command>C:\Windows\System32\netsh.exe</Command>
<Arguments>interface set interface "Ethernet" ENABLED</Arguments>
</Exec>
</Actions>
</Task>