By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

How can I disable a device in windows using python

P: n/a
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

Feb 27 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Feb 27 '07 #2

P: n/a
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/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.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
Feb 27 '07 #3

P: n/a
"Phoe6" <or*******@gmail.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&DEV_4222&SUBSYS_10418086&REV_02\4&214 CFA8C&1&00E2: Intel(R)
PRO/Wireless 3945ABG Network Connection
1 matching device(s) found.

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

C:\>devcon enable *DEV_4222*
PCI\VEN_8086&DEV_4222&SUBSYS_10418086&REV_02\4&214 CFA8C&1&00E2: 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.
Feb 27 '07 #4

P: n/a
On Feb 27, 2:21 pm, Duncan Booth <duncan.bo...@invalid.invalidwrote:
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

Feb 28 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.