473,724 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Feb 27 '07 #1
4 14240
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
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.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
Feb 27 '07 #3
"Phoe6" <or*******@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.
Feb 27 '07 #4
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

Feb 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6488
by: Kevin Altis | last post by:
Does anyone have experience running Python from a USB storage device? Whether it is the need for doing a demo of your application, doing a bit of consulting, or just showing off Python, it would be handy to be able to run Python on machines that don't already have Python installed. I'm thinking about giving this a try, but wondered if anyone is already doing it and the downsides, if any? CD-ROM is not very effective because the media is...
7
10279
by: Fazer | last post by:
Hello, I have a MP3 and I want to access the songs in them. I was wondering if Python could help me do that. I understand that this can be done using Linux by mountig it as a file system, but I am not on Linux and this is mainly for a Windows platform. Can anyone shed some light? Thanks,
10
7212
by: Wouter van Ooijen | last post by:
I want to use Python to interface with an USB HID device (not a keyboard or mouse, just something that uses the HID driver to avoid the need for a specific driver). Is this possible in pure Python on Windows, or even better, in a portable way? Wouter van Ooijen -- ------------------------------------ http://www.voti.nl PICmicro chips, programmers, consulting
0
2147
by: Carl Waldbieser | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** When using urllib2.urlopen() on my Windows 2000 machine at work, I was puzzled that I kept getting back authentication errors from our Internet proxy server (I was trying to contact an internal machine). Upon digging into the code a little, I found that urllib2 was pulling the proxy information out of the Windows registry (Internet Explorer uses these settings). However,...
2
8912
by: RootSpy2006 | last post by:
Hi All, Problem Definition: --------------------- Microsoft Wirelss Keyboard works in BIOS but does not work when booting into windows. Discovered Work-around: ----------------------------- 1.> Open Device Manager(The keyboard device will have an exclamation and
7
13922
by: Michael | last post by:
I'm exploring how to programmatically disable/enable devices in a system using C#. -MH
1
1762
by: walterbyrd | last post by:
I want my python app to read a file from a pocketpc mobile device, if possible. Assume I am running windows-xp, and activesync 3.8. Assume I have "exported" the file. As I understand it, exported files are not really on the PC, even after syncing. You have to use your stylus on the PDA to get to the file in question, then use your PC mouse to drag the file onto the PC. I hate this. As it is, to get to the file, I have to open "my...
1
3977
by: solanki.chandrakant | last post by:
Hi All, i m working on Linux Fedora Core 4. i have to develop one program in that i have device id. Based on given device id i have to enable/disable particular device id. i have to work with this problem using c programming language. If any function/library, how could i do that i don't know. Please, help me.
37
5061
by: Vince C. | last post by:
Hi all. I've installed Bloodshed Dev-C++ on a Windows 2000 SP4 machine. I'm using MinGW 3.4.2. I'd like to temporarily disable standard functions to write to stderr, i.e. for instance redirect stderr to a temporary file (or /dev/null but is there an equivalent under Windows? Is it "nul:") and then to *restore* the default stderr so that standard library functions that write to stderr produce output again.
0
8868
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9243
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9160
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2613
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.