473,403 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Disabling Devices by calling Setupapi.dll, or Converting Devcon to C#

Hello group,

My C# app needs to disable and re-enable devices. I did some research
and found that I could do exactly what I wanted by using Devcon from
the DDK.

Devcon disable =net @ROOT\POSNATMP\0001

Now, the next challenge is getting this to work in my app. Devcon
comes with its C++ source. I see that the function makes SetupDi*
calls to the Setupapi.dll library. I am not quite sure how to do this
in C#.

I followed Vladimir Afanasyev articles and got a little closer. I can
enumerate the devices and properties. Afanasyev mentions, in the user
comments, that you can disable devices as well but does not provide
sample code. This means I am much closer but still not quite able to
toggle the device drivers.

In sum, I am looking for the answer to one of three questions.

1) Does the .Net Framework 2 provide a way to disable/enable devices?

2) If it does not, what is the best way to convert Devcon C++ sample
to a C# app?

3) Alternatively, what could I add to Vladimir Afanasyev's code to
disable/enable devices?

Thanks in advance,

J Wolfgang Goerlich
Related Links:

Microsoft Article 311272, The DevCon command-line utility functions as
an alternative to Device Manager
http://support.microsoft.com/kb/311272

..NET - Diving into System Programming - Part 1, 2, 3
By Vladimir Afanasyev
http://www.codeproject.com/cs/system/divingsysprog1.asp
http://www.codeproject.com/cs/system/divingsysprog2.asp
http://www.codeproject.com/cs/system/divingsysprog2.asp

Jun 4 '07 #1
2 9104
1) Does the .Net Framework 2 provide a way to disable/enable devices?
No
2) If it does not, what is the best way to convert Devcon C++ sample
to a C# app?
P/Invoke is your friend, it allows you to create direct calls to Win32 APIs
and COM components
3) Alternatively, what could I add to Vladimir Afanasyev's code to
disable/enable devices?
n/a

Phil
Jun 4 '07 #2
Phil wrote:
P/Invoke is your friend, it allows you to create direct calls to Win32 APIs
and COM components
Yes, P/Invoke is my friend. That is exactly how I am importing the
Setupapi.dll library and making the API calls. My problem is in how to
correctly format the input to those APIs.

Why do you think Vladimir Afanasyev's article is not applicable?

Regards,

J Wolfgang Goerlich

Jun 5 '07 #3

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

Similar topics

0
by: FloydPW | last post by:
I am attmempting to enable/disable a device in C#. I am able to locate it and tell it to disable, but the device will not disable even upon reboot. I am hoping someone can lead me in the right...
0
by: NeuroScript LLC | last post by:
I have code that enumerates the serial ports. On all windows versions except NT 4.0 it works. In 4.0 I get the following error message: "The procedure entry point SetupDiEnumDeviceInterfaces could...
3
by: Paul | last post by:
Hi I am trying to create an "Update" button for my form. So far I have got it working fine, posting back and updating the record. Great! However, I now want to make it so that when a user...
4
by: louise raisbeck | last post by:
Hi there, I have put some web controls, textboxes and drop down lists, in a Panel, so that under a certain condition i can disable all fields for input. I read in Help that disabling a Panel...
2
by: Charles Law | last post by:
I am looking for a way to manipulate a tape device from within .NET. I see there is the ManagementClass, which I think others have mentioned before, but it is not clear at the moment whether this...
0
by: gewe | last post by:
I am using the following code to enumerate devices on the local computer: ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * from Win32_PnPEntity");...
3
by: stacy | last post by:
I am developing an application that must look out over TCP on an ethernet connection to locate our proprietary devices. The Web application and the devices are communicating over ethernet with...
0
by: BLUE | last post by:
I'll let you know what the dealer and the manufacturer will answer me as soon as possible. As far as now I've been capable or turning ON/OFF: - the RFID reader using dealer supplied...
0
Ali Rizwan
by: Ali Rizwan | last post by:
Hi, How can i control my devices using vb6. Like disabling mouse keyboard speakers etc. Thanx
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.