Python Forum
os.system("netsh interface set interface 'Wi-Fi' enabled")
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
os.system("netsh interface set interface 'Wi-Fi' enabled")
#1
Hello Everyone,
I am running the following code, to disable my Wireless network card.

import os
os.system("netsh interface show interface")
def disable():
    os.system("netsh interface set interface 'Wi-Fi' disabled")
and the Output is : (No error and it doesn't disable my Wifi, and my Wifi NIC name is "W-Fi". So it doesn't do anything)

Output:
Admin State State Type Interface Name ------------------------------------------------------------------------- Disabled Disconnected Dedicated Wi-Fi Disabled Disconnected Dedicated TPALAN Enabled Connected Dedicated TPALANDOC Process finished with exit code 0
Please advise.
Thanks
ANS

**Moderator Note** Fixed your code tags, use python, not quotes around code.
Reply
#2
Is that all your code? A function doesn't do anything if you don't call it.

Sort of like a bike. It won't move anywhere just because you have one, you need to use it for it to move. Otherwise it'll just sit there, in the corner, silently judging you.
Reply
#3
(Jan-16-2019, 06:54 PM)nilamo Wrote: Is that all your code? A function doesn't do anything if you don't call it.

Sort of like a bike. It won't move anywhere just because you have one, you need to use it for it to move. Otherwise it'll just sit there, in the corner, silently judging you.


Hello Nilamo,
Thank you for your correction
import os
os.system("netsh interface show interface")

def enable():
    os.system("netsh interface set interface 'Wi-Fi' enabled")
enable()
This is my actual code.

i also tried
import subprocess

def enable():
    subprocess.call('netsh interface set interface "Wi-Fi" enabled')
enable()
Output:
The requested operation requires elevation (Run as administrator). Process finished with exit code 0
But it is not working. Please advise.

i also tried
import subprocess

def enable():
    subprocess.call('netsh interface set interface "Wi-Fi" enabled')
enable()
Output:
The requested operation requires elevation (Run as administrator). Process finished with exit code 0
I tried to run as administrator in CMD, but didn't work as well.
Please advise.
Thank you.
Reply
#4
(Jan-16-2019, 08:57 PM)aniyanetworks Wrote: I tried to run as administrator in CMD, but didn't work as well.
What does that mean?
Reply
#5
(Jan-16-2019, 10:35 PM)nilamo Wrote:
(Jan-16-2019, 08:57 PM)aniyanetworks Wrote: I tried to run as administrator in CMD, but didn't work as well.
What does that mean?

I mean by that,i tried to run my py script in windows command terminal with as an administrator. I usually use pycharm Text editor.
hope this helps.
Reply
#6
I think you should use enable, disable and not enabled, disabled

netsh interface set interface Wi-Fi enable
Reply
#7
(Jan-17-2019, 01:36 PM)Axel_Erfurt Wrote: I think you should use enable, disable and not enabled, disabled

netsh interface set interface Wi-Fi enable

Hello Axel_Erfurt,
Thanks for respond. As you recommended, tried to enable instant of enabled. but still it didn't work nor it gave me any error message.
On the other hand, when I tried to run the following code in windows terminal it works without python code.
but when I tried to run this code in python it doesn't work.
Quote:netsh interface set interface "Wi-Fi" DISABLED
netsh interface set interface "TPALAN" DISABLED
Reply
#8
What output do you get if you pass a list to subprocess.call()?

>>> import subprocess
>>> help(subprocess.call)
Help on function call in module subprocess:

call(*popenargs, timeout=None, **kwargs)
    Run command with arguments.  Wait for command to complete or
    timeout, then return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])

>>> subprocess.call(['netsh', 'interface', 'set', 'interface', 'Wi-Fi', 'disabled'])

0
Reply
#9
(Jan-17-2019, 04:51 PM)nilamo Wrote: What output do you get if you pass a list to subprocess.call()?

>>> import subprocess
>>> help(subprocess.call)
Help on function call in module subprocess:

call(*popenargs, timeout=None, **kwargs)
    Run command with arguments.  Wait for command to complete or
    timeout, then return the returncode attribute.

    The arguments are the same as for the Popen constructor.  Example:

    retcode = call(["ls", "-l"])

>>> subprocess.call(['netsh', 'interface', 'set', 'interface', 'Wi-Fi', 'disabled'])

0

Hello nilamo, Thanks for taking the time to work on my issues.
I tried your code and gives me the following error
import subprocess
#help(subprocess.call)
subprocess.call(['netsh', 'interface', 'set', 'interface', 'Wi-Fi', 'disabled'])
Output:
The requested operation requires elevation (Run as administrator). Process finished with exit code 0
FYI, I am using Pycharm as text editor. and i have tried to run my python script in the windows command terminal, but still no luck.
Please advise.
Reply
#10
What happens if you run it with admin privileges, as it suggests?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Build a matrix by pressing buttons of an interface in Tkinter which extract data from juandiegopulla 1 153 Sep-13-2021, 07:28 PM
Last Post: deanhystad
  in a login interface when i try login with a user supposed to say test123 but nothing NullAdmin 3 608 Feb-20-2021, 04:43 AM
Last Post: bowlofred
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 8,383 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  Help with User Interface design code ai_masti 0 683 Nov-19-2020, 05:58 PM
Last Post: ai_masti
Question Difference between Python's os.system and Perl's system command Agile741 13 2,590 Dec-02-2019, 04:41 PM
Last Post: Agile741
  AttributeError: 'tuple' object has no attribute 'interface' Kim6071 1 2,214 May-26-2019, 07:54 AM
Last Post: heiner55
  How to rename Network Interface name aniyanetworks 7 2,258 Jan-30-2019, 06:12 PM
Last Post: aniyanetworks
  Interface Arduino and MSSQL using Python MichaelDean 0 1,486 Nov-18-2018, 05:00 PM
Last Post: MichaelDean
  Ioctl Interface mickib1 3 2,375 Jun-23-2018, 03:30 PM
Last Post: mickib1
  lambda-Amazon EC2:Remove instance termination protection if enabled and terminate ins dragan979 0 2,076 Jun-13-2018, 09:48 AM
Last Post: dragan979

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020