How can I disable a device in windows using python

Tim Golden mail at timgolden.me.uk
Tue Feb 27 02:34:09 EST 2007


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:

   http://channel9.msdn.com/ShowPost.aspx?PostID=158340

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/article.asp?EditorialsID=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.Application")
control_panel = shell.Namespace (3)
for item in control_panel.Items ():
   if item.Name == "Network and Dial-up Connections":
     network_connections = item
     break
else:
   raise Exception ("networking not found")

# you now have the networking item

</code>

TJG



More information about the Python-list mailing list