10

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
EMP
  • 59,148
  • 53
  • 164
  • 220

12 Answers12

20

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.

EMP
  • 59,148
  • 53
  • 164
  • 220
  • No, sorry, it's been a while. – EMP Aug 19 '11 at 00:26
  • 1
    Found it! It uses the IP Helper Class http://msdn.microsoft.com/en-us/library/windows/desktop/aa365872(v=vs.85).aspx. Infact! Microsoft released the code of Ipconfig itself in one of the code samples for MSDN_98. It's old but its still used in the current edition. All the routing protcols are done by using Routing protocol located here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb530708(v=vs.85).aspx. I made my own thought this would be useful for anyone else looking for it. – Nightforce2 Jan 17 '12 at 00:17
8

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.

lpfavreau
  • 12,871
  • 5
  • 32
  • 36
5

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 ...)

Johnny
  • 51
  • 1
  • 1
  • Thanks. I can't test it reliably anymore, since the original problem no longer occurs, but this is something I wasn't aware of and it sounds promising. – EMP Jan 14 '10 at 12:37
  • It seems like both of these actions require a reboot of the computer while the repair action in the ui does not. – Zitrax Mar 05 '14 at 09:07
2

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.

chaos
  • 122,029
  • 33
  • 303
  • 309
1

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/

nyet
  • 83
  • 1
  • 9
1

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
Zitrax
  • 19,036
  • 20
  • 88
  • 110
1

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.

Harty
  • 316
  • 2
  • 12
0

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

0
ipconfig /renew
Steven A. Lowe
  • 60,273
  • 18
  • 132
  • 202
0

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)

0

The closest thing I could find on this was. http://msdn.microsoft.com/en-us/library/ff358632(v=vs.85).aspx

Nightforce2
  • 1,426
  • 5
  • 18
  • 31
-1

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>&lt;QueryList&gt;&lt;Query Id="0" Path="System"&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Microsoft-Windows-Power-Troubleshooter'] and EventID=1]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</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>
user253751
  • 57,427
  • 7
  • 48
  • 90