Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Windows XP machine that I'm accessing remotely which has tendancy to get into a weird state with the network connection - when you're on the machine locally it shows as connected still but nothing gets through. Disabling and Enabling the network connection solves the problem. I guess this symptomatic of a more serious problem, but I can't get to the machine to sort it out until at least Monday, so I was hoping to either find some utility or put to together a quick script to test the network connection (i.e. telnet 80 or something) and restart the network connection if possible or else reboot the machine. Googling on this suggests only really complicated lash-ups, and I don't want to lock myself out before I can get to it... Can anyone suggest something simple? Or even a way to automatically restart the connection every couple of hours?

share|improve this question
up vote 1 down vote accepted

If you're going to punt and reboot, at least test the connection first; so if you can't retrieve something over the internet, then reboot. We can quibble about you punting on 2nd down with 70 to go, but it's just silly to punt on every 2nd down.

EDIT: After further reflection and curiosity, here's the PowerShell way of doing this, with some bonus ideas. No need to mess with schedules, it automatically sleeps for three minutes, so just run it once on startup (powershell -File testandpunt.ps1). I've added a simple counter, so it doesn't reboot until three failed attempts. Obviously, change any of these values. Changed to since the latter is probably faster and i'd rather you siphon their bandwidth.


$url = ""
$i = 0 # failure count
    $req.Timeout = 10000 # in milliseconds
    $i=0 # got it, reset failure count
    $i++ # failed, bump failure count
  if( $i -eq 3 ){ # i give up, reboot
    shutdown -r -t 60 -f -c "Lost connection. Rebooting in 60 seconds..."
  Start-Sleep -s 180 # wait a bit

ORIGINAL ANSWER: There are probably better ways, but i've written a little script to only restart if the connection fails. If you don't or can't use vbs, then curl or python or perl or whatever can do the same thing.

So, you'll be able to schedule it tighter--say, every five minutes--to cut down on the restarts and reduce the max time your connection is down.


Set WshShell = WScript.CreateObject("WScript.Shell")
Set http = CreateObject("Microsoft.XmlHttp") "GET", "", FALSE
http.send ""
strData = http.ResponseText
if( len(strData) = 0 ) Then
    Wscript.Echo "Restarting"
    WshShell.Run "%SystemRoot%\System32\shutdown.exe -r -t 600"
End If
set WshShell = nothing
set http = nothing
share|improve this answer
Very nice! Thank you, that is exactly what I was after. – Colin Pickard Feb 26 '10 at 23:16
@Colin - no problem. Have fun! – bill weaver Feb 27 '10 at 5:14
@Colin - added fancy-pants PowerShell script that does the waiting so you don't have to schedule it, adds a retry count, and is generally much better. – bill weaver Feb 27 '10 at 7:23
very slick! I really must have a proper play with PowerShell one of these days. – Colin Pickard Feb 27 '10 at 9:20

From the command prompt you can use:

netsh interface set interface "Local Area Connection " DISABLE

netsh interface set interface "Local Area Connection " ENABLE

You can paste that into a new text file, save with a .BAT or .CMD extension then set up a scheduled task to launch however often you want.

However, I would recommend trying to update the driver and if it doesn't work, buy a PCI network card, you can get cheap ones for around £2 which are more than capable of doing the job.

share|improve this answer

What I've done for now is to schedule the following as a task every 30 mins:

%SystemRoot%\System32\shutdown.exe -r -t 600

So if it dies, worst case I will be back on in under 40 mins. It does mean I've got to be ready with shutdown -a when I'm using it.

Anyone know if it might do any harm to leave your machine rebooting every half hour?

share|improve this answer
@Colin Pickard - i've added a vbs script that restarts only if the connection is down. Save you some restarts and you can schedule your task for every 5 minutes and have quicker turnaround if the connection goes down. – bill weaver Feb 26 '10 at 21:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.