A friend asked me for a program to switch his integrated wifi card off and on. I’ve googled it with no luck. Can someone tell me if there’s any way to do that natively in python?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Does the solution have to be native? I would use a utility called ‘devcon’ which is created by Microsoft. You could use Python to call devcon and parse the output and disable the required device(s).
Here’s an example:
http://en.kioskea.net/faq/1886-enable-disable-a-device-from-the-command-line
You can get the list of network devices with
You can try to parse the one with WiFi in it and the lines that start with PCI.
Or you can do something like:
devcon disable hwids =net, unfortunately this disables the ethernet devices as well.If you need to just disconnect from WiFi you can use
netsh wlan disconnectEDIT: Ok, finally found the perfect solution (IMHO).
You will need to install two packages
pywin32andwmi.Using WMI (Windows Management Instrumentation) bindings for Python this becomes pretty easy.
If it returns a tuple with the first value of (0) it succeeded. Obviously, this must be run as an administrator (otherwise you will get 5 as the return value).