How can I disable a device in windows using python

P

Phoe6

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
 
G

Gary Herron

Phoe6 said:
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
 
T

Tim Golden

Phoe6 said:
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
 
D

Dennis Lee Bieber

You didn't even tell us what operating system you are using, but even

It was implied: "wmi" => Windows Management Interface, as I recall
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.
But the rest I agree with... Regardless of what one tries to do with
Python, the first question to answer is "How would one do this without
Python"
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
D

Duncan Booth

Phoe6 said:
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&214CFA8C&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&214CFA8C&1&00E2: Disabled
1 device(s) disabled.

C:\>devcon enable *DEV_4222*
PCI\VEN_8086&DEV_4222&SUBSYS_10418086&REV_02\4&214CFA8C&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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top