Search The Web

Sunday, March 11, 2012

stop and start network adapters in a batch file or DOS using netsh

Stop and Start Network Adapters in a Batch File or DOS using netsh.


Sometimes you may want to stop and start network adapters from a command line. This is especially true for when you want to use them in a DOS batch file.
To do this we are going to use Net Shell (netsh) which is a powerful command line based tool for managing network properties. net shells capabilities extend far beyond what we are doing here and i encourage you to investigate this further. To get a list of commands try typing " netsh /? " at a command line
netsh /? to display a list of net shell options
netsh /? to display a list of net shell options
Firstly you will want to find the name of the adapter. to do this, open Network and Sharing Center (in Win 7 and Vista) and choose Change adapter settings. Typically, the a LAN connection is named " Local Area Connection " and a wireless connection is named " Wireless Network Connection " . This can also be discerned from looking at an ipconfig read out, where for a LAN connection is will say Ethernet Adapter Local Area Connection " . if doing this remember to drop the Ethernet adapter portion of the name.
Another way to find the name is to open a DOS command and enter netsh interface show interface. The name listed in the interface name is the name of the connection. In this case was are focusing on the Wireless Network Connection
Use netsh interface  show interface  to show interface name in dos / powershell
Use netsh interface show interface to show interface name in dos / powershell
For this example we will use a wireless network adapter with the default name of "Wireless Network Connection"
The command to disable this connection is:
netsh interface set interface "Wireless Network Connection" DISABLE
netsh interface set interface " name" enable to enable interface in dos / powershell
netsh interface set interface " name" enable to enable interface in dos / powershell
to enable the adapter again, the command is:
netsh interface set interface "Wireless Network Connection" ENABLE
netsh interface set interface "<name>" enable to enable network interface is dos / powershell
netsh interface set interface "" enable to enable network interface is dos / powershell
as you can see, this would be really easy to put in a batch file to put in a start up or deploy in other methods.
for a video tutorial on this, please check the youtube video below:


This post can also be located at our sister site www.dizzyit.com at: http://wp.me/p1Zlmi-1u

Sunday, March 4, 2012

start and stop services via batch file / command prompt

start and stop services via batch file / command prompt


To start and stop services with a batch file is very easy and is useful for scheduled tasks where you may want to regularly restart a service for various reasons
Firstly, you need to know the name of the service. to locate this you go to computer management -> services and look for the name of the service you need to restart. In this case we will use the Print Spooler service.
your commands to stop the service are net stop "service name" and your command to start it are net start "service name"
so to restart as a batch file would look like"
@Echo Off
REM this will restart the prince spooler service

net stop "Print Spooler"
net start "print spooler"
exit
as usual you would want to add a remark (REM) to the start of the batch file to describe what you would like to do.
you can combine these commands for restarting complex systems such as IIS. as an exambple, this series of command will restart IIS's web, FTP and SMTP services
@Echo off
REM this restarts IIS's web, SMTP and FTP services
net stop "World Wide Web Publishing Service"
net start "World Wide Web Publishing Service"
net stop "FTP Publishing Service"
net start "FTP Publishing Service"
net stop "Simple Mail Transport Protocol (SMTP)"
net start "Simple Mail Transport Protocol (SMTP)"
so as you can see this is all pretty straight forward stuff. from here you can save the batch file and add it as a scheduled task in windows (more on that later)