5

At my work, there is a company intranet I can connect to, as well as a Wifi network. But, it is company policy that we cannot connect to both networks simultaneously on one machine.

I need to use either network at different times though, and the only way I've been able to do so is by going to "Change Adapter Settings" somewhere in the Network section of Control Panel, then disabling whichever adapter I'm using (either local area network or wifi) and enabling the other one.

As a programmer the repetitiveness and tediousness of this task bothers me, so is there a script I could write to toggle these?

1

2 Answers 2

7

You should look into netsh:

ex: netsh interface set interface "Local Area Connection" DISABLED

(or ENABLED)

create 2 scripts that do an ENABLED on the one you want and DISABLED on the other, and vice versa (or 1 script that first sees which one is up and which is down, and inverts)

This command can also list the state of the interfaces.

But it behaves differently (or uses a different syntax) between several flavors of windows... so you can also have a look at MicroSoft' devcon. Or another possibility: wmic.

Sign up to request clarification or add additional context in comments.

4 Comments

Is there a good way to GET whether it's enabled or disabled, for the sake of just making one script that toggles it?
hmmm, netsh behaves differently on different version of windows. Have a look also at microsoft' devcon. Or another possibility: wmic
I'm pretty sure you know which one is set ^^ But yes, netsh should also show you the informations about the interfaces.
I'll edit my answer to reflect my comment about the other possibilities, for completeness sake
2

You can do this with powershell and the network adapter commandlets.

Disable-NetAdapter: PS C:> Disable-NetAdapter -Name "Ethernet 2"

Enable-NetAdapter: PS C:> Enable-NetAdapter -Name "Ethernet 2"

3 Comments

I'm confused, is powershell something I need to install before I can use these "commandlets"
Oh whoa it's another preinstalled shell. Never knew this existed. Why does it?
It exists to interacting better with .Net objects and run a full object model in a scripting environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.