By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.