Batch file to disable or enable network adapter
Dear all, Is there anyone that knows how to write a batch file to enable / disable local area connection just by 1 click on the batch file? Thank you so much...

Software/Hardware used:
ASKED: June 24, 2010  9:18 AM
UPDATED: April 18, 2013  3:16 PM

Answer Wiki:
Use the netsh command in your batch file: To disable the interface run:
netsh interface set interface "Local Area Connection" DISABLED
To enable the interface run:
netsh interface set interface "Local Area Connection" ENABLED
If the OS is Win XP the above method will probably not work. In that case, here is another (a little more complicated) option that works on XP using VB Script. If the interface is enabled this script will disable it, and it will enable it when it is disabled.
Const ssfCONTROLS = 3 

sConnectionName = "Local Area Connection" 

sEnableVerb = "En&able" 
sDisableVerb = "Disa&ble" 

set shellApp = createobject("shell.application") 
set oControlPanel = shellApp.Namespace(ssfCONTROLS) 

set oNetConnections = nothing 
for each folderitem in oControlPanel.items 
	if folderitem.name = "Network Connections" then 
		set oNetConnections = folderitem.getfolder: exit for 
	end if 
next 
if oNetConnections is nothing then 
	msgbox "Couldn't find 'Network Connections' folder" 
	wscript.quit 
end if 
set oLanConnection = nothing 
for each folderitem in oNetConnections.items 
	if lcase(folderitem.name) = lcase(sConnectionName) then 
		set oLanConnection = folderitem: exit for 
	end if 
next 
if oLanConnection is nothing then 
	msgbox "Couldn't find '" & sConnectionName & "' item" 
	wscript.quit 
end if 

bEnabled = true 
set oEnableVerb = nothing 
set oDisableVerb = nothing 
for each verb in oLanConnection.verbs 
	if verb.name = sEnableVerb then 
		set oEnableVerb = verb 
		bEnabled = false 
	end if 
	if verb.name = sDisableVerb then 
		set oDisableVerb = verb 
	end if 
next 
if bEnabled then 
	oDisableVerb.DoIt()
else 
	oEnableVerb.DoIt 
end if 

wscript.sleep 500
Last Wiki Answer Submitted:  April 18, 2013  3:16 pm  by  Michael Tidmarsh   14,060 pts.
All Answer Wiki Contributors:  Michael Tidmarsh   14,060 pts. , TomLiotta   110,175 pts. , Spacewarrior   15 pts. , Matt Mather   3,610 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

But, I get this answer:

C:Users>netsh interface set interface “Local Area Connection” DISABLE
D
An interface with this name is not registered with the router.

Thanks for the help.

 45 pts.

 

You might want to provide more details.

What is the OS ? (this method won’t work on XP)
Have you checked the interface names ? (ipconfig)

 63,580 pts.

 

You need to actually specify your interface name, it could be called something else, see the output from my Windows machine:

d:Documents and SettingsUserDesktop>netsh interface show interface

Admin State State Type Interface Name
————————————————————————-
Enabled Dedicated Network Connect Adapter
Enabled Dedicated {32DAFD15-86C5-41C3-B398-EF8B4FA4
AAD4}
Enabled Dedicated {64D62236-302F-4DFA-81AD-19E82BB1
DB41}
Enabled Dedicated Wireless Network Connection
Enabled Dedicated Local Area Connection
Enabled Dedicated 1394 Connection
Enabled Internal Internal
Enabled Loopback Loopback

You can see the interface name in the last column.

You can also type simply netsh, then help to see all the commands available in the application.

 3,610 pts.

 

My Windows machine is actually my work PC and it is running XP SP2. As Carlosdl mentioned if you are still having problems then please specify your exact OS.

 3,610 pts.

 

Mattmather, have you tested it on your xp machine ?

I remember that NETSH can’t modify the status of the network interfaces in XP as the OS sees them as “dedicated”.

 63,580 pts.

 

I have used it in the past but not tested on this machine as I am using it. A little google has confirmed an issue as mentioned in .

An alternative suggestion could be to use wmic and there is a pretty darn good demo here:

 3,610 pts.

 

This links should have been MS Support and the alternative at Using wmic

 3,610 pts.

 

Are there any changes that I need to make? Because, when I run this command, it is fail to disable the LAN…
Any further explanation??
Thank you…

 45 pts.

 

Powerofnetworking, what command are you referring to ?

As you can see, at least three options have been mentioned in the answer and discussions.

 63,580 pts.

 

From your latest answer…

 45 pts.

 

So you are using the VB script, right ?

Are you getting errors ? if so, what is the complete error message ?

Please, help us help you.

 63,580 pts.

 

Do you mean that I need to download and install the VBScript first?
After that, only run the batch file that u provided??
Thanks a lot…

 45 pts.

 

This is why I asked about the command you were referring to. And it seems that “your last answer” meant different things for you and for me.

You have to understand that we don’t know what you are doing, and we don’t know the exact results you are getting, and we know nothing about the machine you are doing this on. If you don’t provide more information, we won’t be able to help you.

In the ‘answer’ section I posted a vb script (which I presented as an alternative since the netsh option wouldn’t work on windows xp, although we still don’t know the operating system involved).

If you want to use that option, you just have to create a text file with ‘.vbs’ extension and put the provided script text in there. After saving the file you would only need to double click on it to execute the script.

 63,580 pts.

 

I have got the same error of “Powerofnetworking” (An interface with this name is not registered with the router).
My solution was right click on my “.bat” and choose “Run as Administrator”. Ha, my SO is Windows 7 x86 Ultimate.
Thanks to you all!

 10 pts.

 

for vbs, work great in win xp. thanks,

 10 pts.