views:

4745

answers:

7

Does anyone know exactly what Windows XP does when you click "Repair" on a network connection? I'd like to do the same programatically 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.

A: 
ipconfig /renew
Steven A. Lowe
A: 

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
+6  A: 

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
+7  A: 

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.

Evgeny
A: 

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)

Could you post the code here?
Evgeny
+1  A: 

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
+1  A: 

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