7

How can I, in my C# applictation, read specific information about a device? I have tried WMI and it does not provide the information that I need.

The information that I want is stored in the Details tab of a device and the information I want there is "Parent".

I have also looked in regedit, without any luck.

Afra
  • 2,502
  • 3
  • 24
  • 27
  • I would expect WMI to help on this, are you able to get to the device itself with WMI? if so then share the code and we can see how to retrieve the details... – Davide Piras Aug 04 '11 at 13:32
  • Looking with ProcMon, it looks like it's all Win32 API calls, nothing to do with the registry. – mellamokb Aug 04 '11 at 13:35

2 Answers2

1

Microsoft provides a sample: http://support.microsoft.com/kb/311272

From C#, it might be easier to capture the output of devcon than integrating the APIs. If you feel comfortable with it, C++/CLI is by far the easiest way to get device information into .NET (I've done this before).

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Still not clear.Which commands will show tabs details? @Afra can you paste your sample here , if you are able to succeed in what you are trying ! – Raulp Feb 03 '14 at 07:40
  • @Raulp: `devcon` is not just a handy tool, it is a sample. That means that the source code is available for you to learn from. Why do I get the idea that you haven't even looked at the source? – Ben Voigt Feb 03 '14 at 14:45
  • I looked at the sample examples, and there is no way to retrieve the "power" status (also called power data).Yes ofcourse there is state of the device(status) "driver running" or device status OK.But not the Power data info.(so far I am not able to find). – Raulp Feb 03 '14 at 16:57
  • 1
    @Raulp: Ok. The sample shows you how to get a device information set and device node handle. Then call [`SetupDiGetDeviceProperty`](http://msdn.microsoft.com/en-us/library/windows/hardware/ff551963.aspx) and query [`DEVPKEY_Device_PowerData`](http://msdn.microsoft.com/en-us/library/windows/hardware/ff542586.aspx) Or [`SetupDiGetDeviceRegistryProperty`](http://msdn.microsoft.com/en-us/library/windows/hardware/ff551967.aspx) with `SPDRP_DEVICE_POWER_DATA` – Ben Voigt Feb 03 '14 at 17:04
  • Thanks for the hint, I am able to get the Power State now.! – Raulp Feb 06 '14 at 10:14
0

These APIs should get you going: http://msdn.microsoft.com/en-us/library/ff550630(VS.85).aspx#retrieving_the_parent_of_a_device_inst

Looks like SetupAPI can be used as an alternative on Windows Vista or newer. The above method works on Win2000+

James Johnston
  • 9,264
  • 9
  • 48
  • 76