Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 972
  • Last Modified:

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?
0
pawan-agr
Asked:
pawan-agr
2 Solutions
 
Andre ThibodeauITCommented:
Use netsh

Write a batch script, then use your task scheduler to run it.

ie:

netsh int set interface name="Local Area Connection" admin=disabled
netsh int set interface name="Local Area Connection" admin=enabled

Note: Admin permissions needed for netsh

Andre
0
 
pawan-agrAuthor Commented:
athibodeau:

I ran the command but I received the error.

Here is the screenshot:
http://screencast.com/t/OThmMzI1NG
0
 
Krzysztof PytkoActive Directory EngineerCommented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Andre ThibodeauITCommented:
use "netsh interface ip show config" to quickly show you the interface config.

0
 
pawan-agrAuthor Commented:
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)
0
 
Andre ThibodeauITCommented:
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
0
 
Andre ThibodeauITCommented:
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
0
 
Andre ThibodeauITCommented:
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
0
 
pawan-agrAuthor Commented:
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).
0
 
Andre ThibodeauITCommented:
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

0
 
Andre ThibodeauITCommented:
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
0
 
pawan-agrAuthor Commented:
athibodeau:

Can you please test the DevCon tool and give me a simple guide to follow?
0
 
pawan-agrAuthor Commented:
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.
0
 
Darr247Commented:
No matter what you rename the adapters in Network Connections, that doesn't change the interface name[s], which you can see at the top of the "route print" output (unless they are disabled).

But to start on the devcon method, you need to know the hardware instance IDs of the NICs.
To find the hardware IDs, run

C:\path\where\you\unzipped\devcon\i386_or_ia64\> devcon hwids PCI\VEN*

in a Command Prompt window, then scroll back up and look for "ethernet" or "network" in the name (the "name" will match what it says in 'route print' but devcon needs the hardware instance ID).

If there are too many devices or not enough buffer space in the command window, preventing you from scrolling back far enough to find the NICs' device IDs, you can run

... \> devcon hwids PCI\VEN* > C:\PCI-HWIDS.TXT

then open C:\PCI-HWIDS.TXT in notepad.

It should list 4 to 8 IDs for each device, in varying granularities of uniqueness. To make it work with cards from the same vendor, you'll probably have to go to at least the subsys level to get them unique between the cards.

e.g.
... \> devcon disable "PCI\VEN_xxxx&DEV_xxxx&SUBSYS_xxxxxxxx"

... \> devcon enable "PCI\VEN_xxxx&DEV_xxxx&SUBSYS_xxxxxxxx"

you MUST enclose the IDs in double quotes or it won't look past the PCI\VEN_xxxx part, which if they're both from the same vendor are probably identical between the 2 NICs.
0
 
pawan-agrAuthor Commented:
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. :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now