none
How to get the details for each enumerated device? RRS feed

Answers

  • I can enum system devices, but how to click the each device to get the details, like the link below

    https://www.codeproject.com/articles/14412/enumerating-windows-device

    What APIs to get the details for each device? Are there the sample codes for VB.NET?

     You can also use the CM_Get_DevNode_Property_Keys function to get an array of DEVPROPKEY structures (the supported property keys for the device),  then use the CM_Get_DevNode_Property function to retrieve the actual data of the property.  However,  each property requires you to convert the data to the correct data type.  Some will need to be converted to UIntegers,  some to FileTimes,  some to Lists of strings or just single strings,  and so on...

     Below is a link to an example which probably does pretty much what you want,  including getting the FirstInstallDate property.  The example is part of a larger project i made a while back and have recently been working on so,  i have limited it down to only including the stuff to list the devices and get their properties too.  It is similar to the systems Device Manager (image below).

     This is a Vb.Net example and was built with VS2015 Community.  Hopefully you can open it in whatever version of VS you are using.

    Get Device Properties Example

     This is what the example application looks like...


    If you say it can`t be done then i`ll try it

    • Marked as answer by gaxjyxq Wednesday, January 24, 2018 12:05 AM
    Tuesday, January 23, 2018 9:29 PM
  • Seem there is no the property below in Windows.

        Public Shared ReadOnly Property Device_LastRemovalDate As DEVPROPKEY
           
    Get
               
    Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 103)
           
    End Get
       
    End Property

     That property must not be set for that device but,  it might be for other devices.  I would just leave it in there.  If you noticed,  there are a lot of 'properties' that i declared in the PropertyKeys class but,  not all of them are used for every device type.  That is the reasoning behind using the CM_Get_DevNode_Property_Keys function.  It only gets an array of the properties that are actually set for the device.  If it is not set for the device,  it will not be shown for that device.

     Also,  i mentioned this morning that i would show you how to get a list of the Guid and Pid's for the unknown properties so you can try searching for them on the net.  So,  if you look in the DeviceInfo class,  you will find a Function called 'GetNameFromKey'.  You can modify that function as shown below so that it will write the Guid's and Pid's of only the unknown properties in the Immediate Window.  Then the fun begins,  searching for them.  Some were easy to find and others you may not find.  Some of them may be specific to the device and you wont be able to find.

        Private Function GetNameFromKey(dpk As DEVPROPKEY) As String
            Dim dpks As New PropertyKeys
            Dim ptyp As Type = GetType(PropertyKeys)
            Dim props() As Reflection.PropertyInfo = ptyp.GetProperties
            Dim dpkName As String = dpk.fmtid.ToString
            For Each pi As Reflection.PropertyInfo In props
                If pi.CanRead Then
                    Dim pk As DEVPROPKEY = CType(pi.GetValue(dpks, Nothing), DEVPROPKEY)
                    If pk.fmtid.ToString.ToUpper = dpk.fmtid.ToString.ToUpper AndAlso pk.pid = dpk.pid Then
                        dpkName = pi.Name
                        Exit For
                    End If
                End If
            Next
    
            'if the name was not found and it is still a Guid then write the Guid and the Id to the Immediate Window
            If dpkName = dpk.fmtid.ToString Then
                Debug.WriteLine("Unknown Property:  Guid=" & dpk.fmtid.ToString & "  Pid=" & dpk.pid.ToString)
            End If
    
            Return dpkName
        End Function


    If you say it can`t be done then i`ll try it

    • Marked as answer by gaxjyxq Wednesday, January 24, 2018 9:58 PM
    • Edited by IronRazerz Wednesday, January 24, 2018 10:26 PM Spelling ....
    Wednesday, January 24, 2018 6:42 PM

All replies

  • Gaxjyxg,

    Probably I miss something, it seems you start a discussion about details for enumerated devices.

    But what is it you want to discuss. 

    It seems me more you have a problem for which you have a question?


    Success Cor

    Tuesday, January 23, 2018 8:11 AM
  • I can enum system devices, but how to click the each device to get the details, like the link below

    What is the object being returned in that enum?   The informatino you can extract depends on the object, either directly as object properties, or indirectly as a result of other objects you create from the properties.

    Tuesday, January 23, 2018 8:12 AM

  • What APIs to get the details for each device? Are there the sample codes for VB.NET?

    SetupDiGetDeviceRegistryProperty
    Tuesday, January 23, 2018 8:44 AM
  • Thank you, but seem the API SetupDiGetDeviceRegistryProperty cannot get the info, such as Install date, Last Arrival Date, Is connected..., please view the image.

    Tuesday, January 23, 2018 10:58 AM
  • You get everything with

    SetupDiGetDeviceRegistryProperty

    and

    SetupDiGetDeviceProperty

    Tuesday, January 23, 2018 11:15 AM
  • OK, thank you, i will study it.
    Tuesday, January 23, 2018 12:35 PM
  • You should be able to get these details through WMI queries.

    https://msdn.microsoft.com/en-us/library/aa393964(v=vs.85).aspx

    https://msdn.microsoft.com/en-us/library/ms257340.aspx


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, January 23, 2018 1:09 PM
    Moderator
  • The easiest way is for beginners to use the Microsoft Tool for that. 

    https://www.microsoft.com/en-us/download/details.aspx?id=8572

    Don't look at the enormous Microsoft Add on the page which is completely unrelated.


    Success Cor

    Tuesday, January 23, 2018 5:02 PM
  • I can enum system devices, but how to click the each device to get the details, like the link below

    https://www.codeproject.com/articles/14412/enumerating-windows-device

    What APIs to get the details for each device? Are there the sample codes for VB.NET?

     You can also use the CM_Get_DevNode_Property_Keys function to get an array of DEVPROPKEY structures (the supported property keys for the device),  then use the CM_Get_DevNode_Property function to retrieve the actual data of the property.  However,  each property requires you to convert the data to the correct data type.  Some will need to be converted to UIntegers,  some to FileTimes,  some to Lists of strings or just single strings,  and so on...

     Below is a link to an example which probably does pretty much what you want,  including getting the FirstInstallDate property.  The example is part of a larger project i made a while back and have recently been working on so,  i have limited it down to only including the stuff to list the devices and get their properties too.  It is similar to the systems Device Manager (image below).

     This is a Vb.Net example and was built with VS2015 Community.  Hopefully you can open it in whatever version of VS you are using.

    Get Device Properties Example

     This is what the example application looks like...


    If you say it can`t be done then i`ll try it

    • Marked as answer by gaxjyxq Wednesday, January 24, 2018 12:05 AM
    Tuesday, January 23, 2018 9:29 PM
  • Wow, thank you so much! But some properties have not listed, such as IsConnected, Last Arrival Date.
    Wednesday, January 24, 2018 12:05 AM
  •  some properties have not listed, such as IsConnected, Last Arrival Date.

    Just use the right DEVPROPKEY

    For example, for those ones,

    fmtid = {83da6326-97a6-4088-9453-a1923f573b29}, pid = 15

    fmtid = {83da6326-97a6-4088-9453-a1923f573b29}, pid = 102


    • Edited by Castorix31 Wednesday, January 24, 2018 2:03 AM
    Wednesday, January 24, 2018 12:43 AM
  • Wow, thank you so much! But some properties have not listed, such as IsConnected, Last Arrival Date.

     Do you have any properties showing up in the ListView that have GUID's as property names,  and that have the same value as the IsConnected property in the system's device manager?

     The code gets the names for the properties (seen in listview) from the properties declared in the PropertyKeys class.  So,  if the property is not added into that class,  then the property name is considered unknown and the GUID of the DEVPROPKEY is used for the property name.

     So,  you may just need to add a few property keys into the PropertyKeys class.  I tracked down and added as many as i could and being my Win 7 computer does not have those properties in the system's device manager,  i did not know they existed.

     Anyways,  let me know what i asked and maybe i can help you add it with a little testing on your end.


    If you say it can`t be done then i`ll try it

    Wednesday, January 24, 2018 1:22 AM
  • Thank you, i will test it
    Wednesday, January 24, 2018 10:26 AM
  •  Try adding these into the PropertyKeys class and see if it works for the two properties you mentioned.  The third one was one that was listed on the same page i found the two you mentioned so,  i just threw that in too.

        Public Shared ReadOnly Property Device_IsConnected As DEVPROPKEY
            Get
                Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 15)
            End Get
        End Property
        Public Shared ReadOnly Property Device_LastArrivalDate As DEVPROPKEY
            Get
                Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 102)
            End Get
        End Property
        Public Shared ReadOnly Property Device_LastRemovalDate As DEVPROPKEY
            Get
                Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 103)
            End Get
        End Property
    


    If you say it can`t be done then i`ll try it

    Wednesday, January 24, 2018 11:08 AM
  • This is in Windows 10.

    Wednesday, January 24, 2018 11:09 AM
  •  Well,  i see a few of those that have the same guid as Castorix31 and I have shown for the properties you mentioned so,  i would try adding the 3 'property keys'  as i said in my last post.

     I have t get out of here for right now but,  i can show you how you can get a list of all the GUIDs and their Ids later.  That is how i found a lot of them,  by getting a list of them and searching the internet to see if i could find a name for the properties.


    If you say it can`t be done then i`ll try it

    Wednesday, January 24, 2018 11:22 AM
  • The two properties below work well.

    Public Shared ReadOnly Property Device_IsConnected As DEVPROPKEY
           
    Get
               
    Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 15)
           
    End Get
       
    End Property
       
    Public Shared ReadOnly Property Device_LastArrivalDate As DEVPROPKEY
           
    Get
               
    Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 102)
           
    End Get
       
    End Property

    Seem there is no the property below in Windows.
       
    Public Shared ReadOnly Property Device_LastRemovalDate As DEVPROPKEY
           
    Get
               
    Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 103)
           
    End Get
       
    End Property

    Wednesday, January 24, 2018 12:08 PM
  • Seem there is no the property below in Windows.

        Public Shared ReadOnly Property Device_LastRemovalDate As DEVPROPKEY
           
    Get
               
    Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 103)
           
    End Get
       
    End Property

     That property must not be set for that device but,  it might be for other devices.  I would just leave it in there.  If you noticed,  there are a lot of 'properties' that i declared in the PropertyKeys class but,  not all of them are used for every device type.  That is the reasoning behind using the CM_Get_DevNode_Property_Keys function.  It only gets an array of the properties that are actually set for the device.  If it is not set for the device,  it will not be shown for that device.

     Also,  i mentioned this morning that i would show you how to get a list of the Guid and Pid's for the unknown properties so you can try searching for them on the net.  So,  if you look in the DeviceInfo class,  you will find a Function called 'GetNameFromKey'.  You can modify that function as shown below so that it will write the Guid's and Pid's of only the unknown properties in the Immediate Window.  Then the fun begins,  searching for them.  Some were easy to find and others you may not find.  Some of them may be specific to the device and you wont be able to find.

        Private Function GetNameFromKey(dpk As DEVPROPKEY) As String
            Dim dpks As New PropertyKeys
            Dim ptyp As Type = GetType(PropertyKeys)
            Dim props() As Reflection.PropertyInfo = ptyp.GetProperties
            Dim dpkName As String = dpk.fmtid.ToString
            For Each pi As Reflection.PropertyInfo In props
                If pi.CanRead Then
                    Dim pk As DEVPROPKEY = CType(pi.GetValue(dpks, Nothing), DEVPROPKEY)
                    If pk.fmtid.ToString.ToUpper = dpk.fmtid.ToString.ToUpper AndAlso pk.pid = dpk.pid Then
                        dpkName = pi.Name
                        Exit For
                    End If
                End If
            Next
    
            'if the name was not found and it is still a Guid then write the Guid and the Id to the Immediate Window
            If dpkName = dpk.fmtid.ToString Then
                Debug.WriteLine("Unknown Property:  Guid=" & dpk.fmtid.ToString & "  Pid=" & dpk.pid.ToString)
            End If
    
            Return dpkName
        End Function


    If you say it can`t be done then i`ll try it

    • Marked as answer by gaxjyxq Wednesday, January 24, 2018 9:58 PM
    • Edited by IronRazerz Wednesday, January 24, 2018 10:26 PM Spelling ....
    Wednesday, January 24, 2018 6:42 PM
  • Thank you so much.
    Wednesday, January 24, 2018 9:58 PM
  • The code below works well also, thank you.

     Public Shared ReadOnly Property Device_LastRemovalDate As DEVPROPKEY
           
    Get
               
    Return New DEVPROPKEY(New Guid("83da6326-97a6-4088-9453-a1923f573b29"), 103)
           
    End Get
       
    End Property

    Thursday, January 25, 2018 3:21 AM