Link to home
Start Free TrialLog in
Avatar of pawan-agr
pawan-agrFlag for Nepal

asked on

How to schedule automatic enable/disable of LAN connections

I have two internet connection attached with two different lan cards. Lan1 and Lan2

I want to automatically enable Lan1 From 10 AM to 6 PM and then disable Lan1 and enable Lan2 from 6PM to 10 AM.

How can I do that?
SOLUTION
Avatar of Andre Thibodeau
Andre Thibodeau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pawan-agr

ASKER

athibodeau:

I ran the command but I received the error.

Here is the screenshot:
http://screencast.com/t/OThmMzI1NG
Avatar of Krzysztof Pytko
interface name should be replaced by NICs name (you probably changed your default name or they have order numbers i.e. Local Area Network 1)

prepare 2 bat or cmd files, one:
netsh int set interface name="LAN1" admin=disabled
netsh int set interface name="LAN2" admin=enabled

second:
netsh int set interface name="LAN1" admin=enabled
netsh int set interface name="LAN2" admin=disabled

where LAN1 and LAN2 are your connections. Run ipconfig /all in command-line and check what names they have.

and set a scheduled tasks on that PC/server on administrative rights.
use "netsh interface ip show config" to quickly show you the interface config.

I have renamed my NICs name to "NTC". So, it's not the wrong name problem.

If I use any other arbitary name instead of NTC then I get this error.
"An interface with this name is not registered with the router."

So, I'm 100% sure that, it's not the wrong name problem.

I'm still getting the same error as I shown in the screenshot above.

(I'm using windows xp and logged in with the administrator account)
netsh needs administrative permissions

Open your cmd prompt as an administrator  "run as administrator", then run your script.

once you get script running, you can tell task scheduler to run as admin.

Andre
here is one of my scripts for my dell 1390 wireless adapter,  c:\bin\dell1390.cmd

netsh interface ipv4 set address "Dell 1390" admin=enable
netsh interface ipv4 set address "Dell 1390" static 192.168.3.201 255.255.255.0 192.168.3.1 1
netsh interface ipv4 set dns name="Dell 1390" source=static addr=192.168.3.1
netsh interface ipv4 add dnsservers "Dell 1390" 8.8.8.8 index=2

I then created a shortcut to the script.  In the shortcut properties you can go in to advanced and runas administrator.

Andre
sorry typo in last message.  should read as.  (copy and paste error)

netsh interface set interface name="Dell 1390" admin=enable
netsh interface ipv4 set address "Dell 1390" static 192.168.3.201 255.255.255.0 192.168.3.1 1
netsh interface ipv4 set dns name="Dell 1390" source=static addr=192.168.3.1
netsh interface ipv4 add dnsservers "Dell 1390" 8.8.8.8 index=2
athibodeau:

I'm still getting the exact same error even running the cmd as administrator.

Does this command work properly in windows XP?

This forum post says:
http://www.compatdb.org/forums/topic/26746-disabling-and-enabling-network-connections-using-cli/
(for others interested, the command works fine with Windows Server 2003, and the version of netsh in XP may not support disabling in this fashion yet).
good question.  I tried the command on my XP box and got same results as you, but other OS's like Windows 2003, 2008, 7, work fine.

I would venture to guess the admin=disabled/enabled is not supported with Windows XP.  Even though it is listed.  I see lots of posts with people having a similar issue with XP.

So...  Looks like netsh is not for you.

Take a look at using devcon, with devcon you can enable and disable devices directly to the device manager.  I have never tried this with a network adapter, but it should work.

http://support.microsoft.com/kb/311272

First query the devices and look for the HardwareID
devcon hwids =net

once you have the HardwareID of the adapter.
devcon disable HardwardID

Andre

Here is another idea.

I would imagine you want to change your default gateway at certain time of day.

Instead of disabling and enabling the adapters, try changing the default gateway using netsh.

something like...
netsh interface ip set address "Local Area Connection 1" static 192.168.1.100 255.255.255.0
netsh interface ip set address "Local Area Connection 2" static 192.168.2.100 255.255.255.0 192.168.2.1 1  (note the gateway 192.168.2.1)

then the reverse to switch gateways
netsh interface ip set address "Local Area Connection 1" static 192.168.1.100 255.255.255.0 192.168.1.1 1
netsh interface ip set address "Local Area Connection 2" static 192.168.2.100 255.255.255.0

Andre
athibodeau:

Can you please test the DevCon tool and give me a simple guide to follow?
Changing the default gateway is a nice idea but it will create confusion as I won't precisely know from which connection the internet is coming from. I think it will be great to use DevCon instead.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you athibodeau and Darr247. You both have helped me a lot with this.

I have splitted the points in both of you.

athibodeau, you put in lots of efforts here but unfortunately your solution didn't work in windows xp. I appreciate all your help.

Darr247: Your solution worked beautifully and I'm ready to implement it. :)