A command line method to reattach to networks
This routine does the same thing as the Windows Network Repair function, but from the command prompt. Now why is this important? Well, it is VERY important when you have effected network changes, or physically had someone detach the computer from one network and attach it to another. When this is done, the computer has to know to forget everything it knew about the old network and learn what it can from the new network. Double clicking on a short cut to this batch file can take care of that and it is much simpler than leading someone through the steps to get to the network repair option.
Concepts Demonstrated: Network manipulation
Concepts Demonstrated: Quiet Parameter
::@Echo off ::************************************************************************* :: This Batch file performs the rough equivelant of a Windows XP SP1 :: Network Connection Repair. :: :: Usage: :: NetworkRepair <-- Prompts for permission & repairs all networks :: NetworkRepair [ConnectionName] <-- Prompts & repairs one network :: NetworkRepair Quiet <-- Does Not Prompt (Quiet is Case Sensitive) :: NetworkRepair Quiet [ConnectionName] <-- Repairs only one network :: :: A Windows Network Connection Repair (Right click on the Local Area :: Connection and choose Repair) performs a series of commands that allows :: a computer to rebuild a its connection to the network. The commands :: that are invoked by Repair are included below in their command-line :: equivalents. The only current difference is that the Repair process :: first checks whether DHCP is enabled and then, if enabled, it issues a :: broadcast renew to refresh the IP address. This will cause the :: computer to accept a lease from *any* DHCP server that is on the network. :: You cannot do that from the command line. In contrast, a unicast renew :: (as done through ipconfig /renew) will only renew the existing lease :: from the currently used DHCP server. I've tried to work around that :: difference calling ipconfig /release. Hopefully, putting the :: ipconfig /renew further down in the batch file will cause a broadcast :: request for a new IP address. I do not know if that will happen or not. :: In any case, this would only affect the behavior of the repair if your :: network has multiple DHCP servers. :: :: In addition, a normal repair is performed for one connection at a time. :: This batch file will repair all network connections unless you specify :: the mask to use for finding the correct networks. Like so: :: NetworkRepair Wi* <-- Repair any connection that has its name :: starting with "Wi" :: NetworkRepair Quiet *Con* <-- Quietly repair all connections with, :: "Con" anywhere in the name. Examples :: include "Local Area Connection 1" or :: "Local Area Connection 2":: :: NetworkRepair quiet <-- Repair all networks named "quiet" :: :: :: Author - Brian Layman :: Created - 5/29/2003 :: Last Modified - 7/27/2005 :: :: License - If this helps you - Great! Use it, modify it share it. :: :: Indemnity - You're playing with network settings and clearing caches. :: That means that if your settings are messed up on this computer or any :: of your network servers or routers, running this batch may cause it to :: see even fewer network resources from this computer. This batch file :: makes the computer forget everything it ever knew about the way the :: network was working before. When it asks the routers and servers for new :: information, that information must be correct for your problem to go away. :: :: Use this batch file at your own risk. I'm only calling built-in Windows :: commands, but if a typo or service pack change affects what this routine :: does, it is not my fault. In fact, you should just stop right now and :: not run this file. For if it causes blue smoke to be emitted from your :: network card, if it resets your home site to HowToKillMyBoss.com, or if :: it makes your sister break up with her lawyer boyfriend and start dating :: a caver, it is not my fault. (Actually that last one might be an :: improvement, but it is still not my fault.) :: :: Uses - This routine allows you to automate switching from one network :: connection to another simply by double-clicking a link on the desktop. :: It may also be useful in performing quick repairs of network connections :: rather than guiding your relative/friend/spouse through the process over :: the phone. :: :: Donations - If this batch file really helps you out, feel free to make a $5 :: (US) donation via Paypal to Brian@TheCodeCave.com or just send a Thank :: You via email to that address and include your country of origin. :: :: MD5 - The correct MD5 is available at: :: http://www.The-WildWest.com/Queeg/NetworkRepair :: :: Enjoy! :: ::************************************************************************* :: ************************************************************************* :Quiet Check :: Check for the Quiet password. :: ************************************************************************* :: Put a bracket around the %1 to trap for empty values and to allow the :: string comparison to work if [%1] == [Quiet] GOTO :TheWorks :: ************************************************************************* :: ************************************************************************* :TheWarning :: :: Display some info about the program and also allow several ways to :: abort an accidental launch. :: :: ************************************************************************* Echo. Echo This batch file will reset your network connection. Echo. Echo. By running it you're playing with network settings and clearing caches. Echo. That means that if your settings are messed up on this computer or any Echo. of your network servers or routers, running this batch may cause it to Echo. see even fewer network resources from this computer. This batch file Echo. makes the computer forget everything it ever knew about the way the network Echo. was working before. When it asks the routers and servers for new Echo. information, that information must be correct for your problem to go away. Echo. Echo. Use this batch file at your own risk. I'm only calling built-in Windows Echo. commands, but if a typo or service pack change affects what this routine Echo. does, it is not my fault. In fact, you should just stop right now and Echo. not run this file. For if it causes blue smoke to be emitted from your Echo. network card, if it resets your home site to HowToKillMyBoss.com, or if Echo. it makes your sister break up with her lawyer boyfriend and start dating Echo. a caver, it is not my fault. (Actually that last one might be an Echo. improvement, but it is still not my fault.) Echo. @pause :: ************************************************************************* :TheWorks :: :: Let the fun begin! :: :: ************************************************************************* if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Release the DHCP lease - NOT PART OF REPAIR if NOT [%1] == [Quiet] ipconfig /release %1 if [%1] == [Quiet] ipconfig /release %2 if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Flush the ARP cache arp -d * if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Flush the NetBIOS cache nbtstat -R if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Flush the DNS cache ipconfig /flushdns if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Request a new the DHCP lease - NOT PART OF REPAIR if NOT [%1] == [Quiet] ipconfig /renew %1 if [%1] == [Quiet] ipconfig /renew %2 if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Re-register with WINS nbtstat -RR if NOT [%1] == [Quiet] Echo. if NOT [%1] == [Quiet] Echo * Re-registers with DNS ipconfig /registerdns if [%1] == [Quiet] CLS :: ************************************************************************* :TheEnd :: :: So long and thanks for all the fish! :: :: *************************************************************************