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

J

jwgoerlich

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
 
P

Philip Doragh

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
 
J

jwgoerlich

Phil said:
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
 

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

Top