How can I disable a device in windows using python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phoe6

    #1

    How can I disable a device in windows using python

    Hi all,
    I am trying to disable the NIC card (and other cards) enabled in my
    machine to test diagnostics on that card.
    I am trying to disable it programmatic using python. I checked python
    wmi and i could not find ways to disable/enable, (listing is however,
    possible).

    Where should I look for to enable/disable devices in python.

    Thanks,
    Senthil

  • Gary Herron

    #2
    Re: How can I disable a device in windows using python

    Phoe6 wrote:
    Hi all,
    I am trying to disable the NIC card (and other cards) enabled in my
    machine to test diagnostics on that card.
    I am trying to disable it programmatic using python. I checked python
    wmi and i could not find ways to disable/enable, (listing is however,
    possible).
    >
    Where should I look for to enable/disable devices in python.
    >
    Thanks,
    Senthil
    >
    >
    You didn't even tell us what operating system you are using, but even
    so, I'm going to say you probably won't find a Python function to do
    this. However, if you tell us how you would disable a card from outside
    of Python, we'll see if we can find a way to do it from within Python.

    Things you might want to tell us:

    What OS.
    What device(s)
    Exactly what "disable" means for each.
    How the OS allows you to enable/disable each.
    Anything else that might help us.


    Gary Herron

    Comment

    • Tim Golden

      #3
      Re: How can I disable a device in windows using python

      Phoe6 wrote:
      Hi all,
      I am trying to disable the NIC card (and other cards) enabled in my
      machine to test diagnostics on that card.
      I am trying to disable it programmatic using python. I checked python
      wmi and i could not find ways to disable/enable, (listing is however,
      possible).
      Since you mention WMI I'm going to assume you're on
      Windows (although if you hadn't we'd have had no idea!).

      Running the terms: wmi disable network card
      past Google came up with this page:

      Browse thousands of hours of video content from Microsoft. On-demand video, certification prep, past Microsoft events, and recurring series.


      where the first answer to the question "Is there any way to
      programatically disable an NIC" points us to this page:

      http://www.mcpmag.com/columns/articl...itorialsID=619

      which uses the Shell application object to automate the control
      panel (and, by the way, I'd no idea you could do this).

      You should be able to recreate this fairly easily from
      Python using the pywin32 extensions, and in particular the
      win32com.client tools. To get you started:

      <code>
      import win32com.client

      shell = win32com.client .Dispatch ("Shell.Applica tion")
      control_panel = shell.Namespace (3)
      for item in control_panel.I tems ():
      if item.Name == "Network and Dial-up Connections":
      network_connect ions = item
      break
      else:
      raise Exception ("networking not found")

      # you now have the networking item

      </code>

      TJG

      Comment

      • Duncan Booth

        #4
        Re: How can I disable a device in windows using python

        "Phoe6" <orsenthil@gmai l.comwrote:
        Hi all,
        I am trying to disable the NIC card (and other cards) enabled in my
        machine to test diagnostics on that card.
        I am trying to disable it programmatic using python. I checked python
        wmi and i could not find ways to disable/enable, (listing is however,
        possible).
        >
        Where should I look for to enable/disable devices in python.
        >
        Assuming you mean windows:

        If you don't mind doing it by spawning an external program try
        downloading devcon.exe from Microsoft's website
        (http://support.microsoft.com/kb/311272).

        Using devcon you can enumerate devices, enable or disable them and a
        variety of other things. For example, on my current machine I can
        disable or enable my wireless card with:

        C:\>devcon find *DEV_4222*
        PCI\VEN_8086&DE V_4222&SUBSYS_1 0418086&REV_02\ 4&214CFA8C&1&00 E2: Intel(R)
        PRO/Wireless 3945ABG Network Connection
        1 matching device(s) found.

        C:\>devcon disable *DEV_4222*
        PCI\VEN_8086&DE V_4222&SUBSYS_1 0418086&REV_02\ 4&214CFA8C&1&00 E2: Disabled
        1 device(s) disabled.

        C:\>devcon enable *DEV_4222*
        PCI\VEN_8086&DE V_4222&SUBSYS_1 0418086&REV_02\ 4&214CFA8C&1&00 E2: Enabled
        1 device(s) enabled.

        The most tricky bit is finding the correct id in the first bit, just do
        a wildcard find command and look for something appropriate. The enable
        and disable are exactly the same as the equivalent commands from the
        network connections window or the device manager. Oh, and don't forget
        if you want to use the full id for a device you'll have to escape the &
        characters or quote the argument.

        Comment

        • Phoe6

          #5
          Re: How can I disable a device in windows using python

          On Feb 27, 2:21 pm, Duncan Booth <duncan.bo...@i nvalid.invalidw rote:
          Hi all,
          I am trying to disable it programmatic using python. I checked python
          wmi and i could not find ways to disable/enable, (listing is however,
          possible).
          >
          Where should I look for to enable/disable devices in python.
          >
          Assuming you mean windows:
          >
          If you don't mind doing it by spawning an external program try
          downloading devcon.exe from Microsoft's website
          (http://support.microsoft.com/kb/311272).
          Thanks for the reply, this is very helpful.

          Thanks,
          Senthil

          Comment

          Working...