If you are willing to spend few minutes for this solution, continue reading. It involves firing a batch file based on event log entries using Task Scheduler.
1. Create a batch file named “Wireless_Disable.bat” with the following contents. Open Notepad, copy/paste the following text and save it as above file name.
netsh interface set interface “Wireless Network Connection” Disable
2. Create another batch file named “Wireless_Enable.bat”. Open Notepad, copy/paste the following text and save it as the above filename.
netsh interface set interface “Wireless Network Connection” Enable
3. Open Event Viewer. Click Start Orb/button and type Event Viewer and select the “Event Viewer” application from search results.
4. Expand Windows Logs and select System.
5. I would suggest unplug your network cable from your laptop and plug back in. Click on Filter current log option in Actions pane. In Event ID text box (in the middle), type 9,4 to filter by event id 9 & event id 4. Click OK.
6. Find Event Id 9 from the filtered list and double click to open it. Make sure this event is for your correct wired network card. Note down the Source value. In my case it is b57nd60a. Click Close button to close the event properties window.
7. Leave the Event Viewer window as it is. Click Start orb/button again and type Task Scheduler. Select Task Scheduler application from search results.
8. Click Task Scheduler Library on your left pane. Click on Create Basic Task.. on the Actions pane to create a new scheduled job.
9. On Create a Basic Task section, Type a name (Dock the Laptop) in Name field and type some description about this task. Click Next.
9. On Trigger section select When a specific event is logged options and click Next.
10. On When an Event is Logged section Select Log as System, Select Source same as you noted down in step 6, and type event ID as 9.Click Next.
11. On Action section Select the option Select a program and click Next.
12. On Start a Program section click on Browse… button and select the batch file you created in step 1. Click Next.
13. Select the check box for Open the Properties dialog for this task.. Click Finish button on Finish section.
14. On the task properties dialog box, select the check box for Run with highest privileges and click OK to close.
15. Create another basic task by do the steps 7 through 14 again. On Step 9 type task name as “Undock the laptop”. On step 10, type event id as 4 instead of 9.
16. THAT’S IT. Task will automatically fired when you plug and unplug the network cable on your laptop (or dock and undock it).
Try unplugging the network cable from wired network card and watch your wireless network card is enable and vice versa.
Warning: When you change your password for your domain user account you need to update the new password on these two scheduled tasks.
Wonderful — simple, elegant and efficient solution. Thanks a lot for the tip! It works like a charm for me.
Note thought that the event source (e1cexpress) and the event IDs (27,3) are different in my case — they seem driver specific.
As one improvement, the batch scripts can be avoided completely by directly putting the info into the task definition:
Script/program:
C:\Windows\System32\netsh.exe
Add arguments:
“interface set interface “Wireless Network Connection” Disable”
You may want to like your post under:
http://social.technet.microsoft.com/Forums/en-SG/w7itpronetworking/thread/ce68f13e-26f2-433c-b25c-acdbb0c25774
to reach more people.
Your solution avoids that i have to resort to commercial solutions:
http://wlanbook.com/bridgechecker/
http://www.wirelessautoswitch.com
I have created two bat files –
netsh interface set interface “Wireless Network Connection” Disable
and
netsh interface set interface “Wireless Network Connection” Enable
these have been placed in task scheduler under create a basic task. I have tried both of these in cmd prompt but they still don’t work.
Can anyone please advise me.
Jayesh, maybe you’ve renamed your WLAN adapter from “Wireless Network Connection”? Mine for example is named “WiFi” so that’s what I need to put in my batch files.
Also, you may run into the quotations in the Action problem (0x1 in task last results – http://support.microsoft.com/kb/951246). You may need to rename your wireless adapter to something without spaces so that you don’t need to include quotes.
Thanks for this, it has helped a great deal.
Instead of disabling the adapter in my case I have done a disconnect on the WiFi connection.
netsh wlan disconnect
Nice tip, however I found that
“netsh interface set interface “[Wireless NIC Name]” Disable”
didn’t work for me but
“netsh interface set interface name=”[Wireless NIC Name]” admin=DISABLED”
did work.
I also found that “wmic path win32_networkadapter where NetConnectionID=”[Wireless NIC Name]” call disable” also worked.
Thanks for tip.
what happens if i don’t find the event ID 9????
I also have no event id 9 or 4 appear..
The event ID completely depends on your hardware configuration. See for example in my post (11/14/11), I got different events from a different system even.
If you do not get the ID’s described, my recommendation is to:
a) skip step (5) which applies a filter
b) Unplug and plug your Ethernet cable a few times.
– watch the log messages, each time you plug / unplug a new log message should be generated
– repeat until you found the right source and event ID
Thanks Gunar. Please follow Gunar’s advice.
I would recommend running this as SYSTEM instead so changing your domain password isn’t required and putting the actual netsh command into the task so there are not additional files you have to deploy just these two commands in a MSI/psexec/SCCM deploy/base image:
schtasks /Create /XML wirelessoff.xml
schtasks /Create /XML wirelesson.xml
(These xml files would be your export of the tasks you created manually in the Task Scheduler)
I will be using this for my Latitude E6500 series workstations that don’t have the great driver option the 6510 and 6520’s have
Great post…Unfortunately we weren’t able to get the consistent results we needed using scripts. We ended up using a 3rd party solution http://www.accessity.com.au/1Net.htm
Great post – one quick obvious note – if you copy/paste from this website, the quotes will be invalid (they’ll be the open quotes/close quotes, you need straight quotes) – make sure to retype the quotes yourself or this won’t work.
I modified this a bit to disable my wireless adapter upon sleep and re-enabling it upon wake. (Network issue workaround…)
A related post can be found here to show you how to run tasks on sleep and on wake:
http://superuser.com/questions/321151/how-to-execute-a-script-on-sleep-hibernate-resume-and-shutdown
My wired LAN card does not seem to send an event on connection, only on disconnection.
I was able to find the proper Event IDs that I needed, but when I go to the Task Scheduler, I do not have the option to trigger by Event ID. My only options are” “Daily, Weekly, Monthly, One time, When computer starts, On Logon.” Any idea as to why I do not have the “Specific Event Logged” option?
how did you find your Event ID?
Manually disable and enable wireless and wired network cards and watch event logs for event ids.
I tried that but I can’t find 9 on a fujitsu Lifebook s760.
just found out that you can use the 27 e1kexpress to trigger.
Hi This is a great post! But the script is bounded for one pc. Since i need to find the event viewer for each and every pc. Do you have a suggestion for multiple pc’s?
@Venkat – This would probably only work well if you had a single type of hardware on the network. You’d then push out the tasks via Group Policy Preferences. It’s a nice solution, but thanks @win7tg for posting that link to Accessity. I think we’ll end up going down that route for our requirements as it does this and more.
Daniel I am trying to find out out how to this via Group Policy Preferences but cant seem to find the option to place the trigger for the source… I am using this URL as reference. https://technet.microsoft.com/en-us/library/cc725745.aspx. Any ideas
This pretty nice and easy, but the event id’s you are using are hardware and/or driver dependent. The hardware independent event id’s I am using are 10000 and 10001 can be found under “Applications and Services Logs/Microsoft/Windows/NetworkProfile”
The first problem I then faced was that it disabled the WLAN interface everytime any network connection is made. I ended up writing a powershell script, which determines the LAN adapter, WLAN adapter and the connection state of the LAN adapter. If the latter is connected (via cable) it will disable WLAN, if it is disconnected (cable removed) it will enable WLAN.
The advantage of my approach is that it’s hardware independent and works on Windows Vista, Windows 7, Windows 8 and Windows 8.1. Furthermore the script is also independent of the name of the wireless network connection. Even if you rename it, it will still find the correct wireless adapter.
If anybody is interested in this script and want to know more details, let me know.
Erik I am very interested in the script and details. We must make sure only one network is available at a given time due to security rules. I know – two doesn’t mean a bridge or true risk, but in a sense, it’s still not a good thing. For us it’s a matter of rule/policy, etc. and as such it must be complied with or face consequences such as loss of connection to the forest.
i would like to know the script
Hi Erik,
I would love to have a look at your script; I’m currently struggling with finding the best solution to this issue with wired vs wireless connections.
Thank you!
//Martin
Erik I would love to see your script. Do you still have it. I am trying to find a script that is hardware independent
This works great except for uppon boot up. Any idea how i can add something to disable wireless uppon boot if ethernet is present?
Same issue here, we may be looking at a third party software solution.
It’s not working 😦
At source says: Service Pack Installer. I do not have a source value.
If any idea, please advice
Thanks
When I dock my laptop, the wired connection is made with this configuration. However, when I undock at this time I am having to manually enable the wireless connection through Device Manager. I do have both Tasks in place on the events. Any ideas? I am using a Lenovo Thinkpad T430 and my event IDs at under 27 and 33. My Source is e1cexpress. Thanks for any advice.
Nevermind…it began working. Seemed as if I had to dock and undock a few times for it to kick in! This works great! I only had to make a few minor adjustments such as changing the parenthesis and WLAN name.
Awesome !!!! Works fine on DELL E7440 and E7240 we have 200x Notebooks
now we can handle it very nice !!!
Those models should have a built in NIC/WFI changer built into the NIC properties under the “Change adapter settings” of “network & sharing center”
Yes it worked on one machine but I am trying to get it pushed out via GPO to several machines. Did you get it to work via GPO
don’t forget to untick the Stop if the computer switches to battery power option under the conditions tab for the un-docking task