473,320 Members | 2,110 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,320 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 9093
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.