VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

  1. #1
    Join Date
    Feb 2012
    Posts
    9

    VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    Hi Guys,

    I'm writing a Windows Forms application in VB.Net 2010. The application's purpose is to recreate the Device Manager in VB.Net. The idea here is to capture the information provided by Device Manager and store it in a database. In turn this information could be used as a configuration management tool.

    My device tree is coming along nicely, with one minor exception. There are hidden devices that Device Manager does not display by default. Show Hidden Devices causes Device Manager to display these devices. My Device Manager displays them by default. I want to duplicate the Device Manager behavior of being able to hide and display these devices in my appilcation. I have had some success with this task in that I am able to hide the Plug and Play devices that are marked as hidden by windows by use of the "Don't Display In DM" flag. There is the small issue of the Non Plug and Play Device Class. My question is this... Is there a similar flag for Non Plug and Play devices? I have found a reference to the PNP_DEVICE_STATE and IRP_MN_QUERY_PNP_DEVICE_STATE IRP. It contains a flag

    PNP_DEVICE_DONT_DISPLAY_IN_UI. My problem is that I cannot find any guidance as to the structure of this API declare and the coding needed to use it. I'm not even sure if this API will be helpful in accomplishing my task. I want to hide the Non Plug and Play devices and device class in my tree. Can someone please assist me with the locating an API that will accomplish this and the proper coding of the API in VB?

    I am using Visual Studio 2010 Ultimate and Running Windows 7 Ultimate with all Service Packs and updates applied.

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,891

    Arrow Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    It would help to know exactly how you're querying the device information, as there are a few ways to do this. Post your code if you're comfortable.

    Like you said, you can look for the "LegacyDriver" device class to determine if the device is non-PnP. Assuming you are using the Driver api's or WMI, you should be able to use the same method you're already using to determine if the "Don't Display In DM" flag is set for a non-PnP driver/device.

    While a non-PnP device driver can definitely register with the PnP manager, I'm not sure if it can specify the "Don't Display In DM" field. My assumption is that it can, but I can't find any literature one way or the other.

    For those following, when I say "Don't Display In DM", I'm talking about one of the following fields:

    1) PNP_DEVICE_DONT_DISPLAY_IN_UI of PNP_DEVICE_STATE
    2) NoDisplayInUI of DEVICE_CAPABILITIES
    3) DN_NO_SHOW_IN_DM in cfg.h
    Last edited by Craig Gemmill; February 27th, 2012 at 08:30 AM.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Feb 2012
    Posts
    9

    Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    I am using Win32 API calls to get the information about the device classes and devices. Querying the device capabilities only seems to work for the PNP devices. The Non PNP devices are a different story.

    This is the API call that gets the information for a given device:

    Friend Sub New(ByVal hInfoSet As IntPtr, ByVal instanceInfo As DevInfoData)

    Me.ptrDeviceInfoSet = hInfoSet
    Me.devInfoData = instanceInfo
    Me.lstProperties = New Dictionary(Of DevicePropertyID, Object)()

    If NativeMethods.CM_Get_DevNode_Status(Me.difFlags, Me.dipProblem, Me.devInfoData.InstanceID, 0) = ConfigResult.Success Then
    If (Me.difFlags And DeviceInstanceFlags.HAS_PROBLEM) = 0 Then
    Me.dipProblem = DeviceInstanceProblem.NO_PROBLEM
    End If
    Else
    Me.difFlags = DeviceInstanceFlags.HAS_PROBLEM
    Me.dipProblem = DeviceInstanceProblem.NO_PROBLEM
    End If

    End Sub

    This is the Visible property I created to determine if a given device is hidden or visible:

    Public ReadOnly Property Visible() As Boolean

    Get
    If (Me.difFlags And DeviceInstanceFlags.NO_SHOW_IN_DM) = DeviceInstanceFlags.NO_SHOW_IN_DM Then
    Me.blnVisible = False
    Else
    Me.blnVisible = True
    End If

    Return Me.blnVisible
    End Get

    End Property


    Here's the code used to get the Device Classes and display them in the Treeview:


    Public Sub Display(ByRef tvwTreeView As TreeView)

    Dim tvwRootNode As New TreeNode
    Dim tvwDeviceClassNode As New TreeNode

    tvwTreeView.BeginUpdate()
    tvwTreeView.Nodes.Clear()

    tvwRootNode = New TreeNode
    With tvwRootNode
    .Name = "[Root}"
    .Text = Environment.MachineName
    End With
    tvwTreeView.Nodes.Add(tvwRootNode)
    For Each curDeviceClass As DeviceClass In DeviceClasses
    If curDeviceClass.Present Then
    For Each curDevice As Device In curDeviceClass.Devices
    If curDevice.Visible Then
    tvwDeviceClassNode = New TreeNode
    With tvwDeviceClassNode
    .ImageKey = curDeviceClass.Description
    .SelectedImageKey = curDeviceClass.Description
    .Text = curDeviceClass.Description
    .Name = "[DeviceClass][" & curDeviceClass.Description & "]"
    .Tag = "[DeviceClass][" & curDeviceClass.Description & "]"
    End With
    tvwRootNode.Nodes.Add(tvwDeviceClassNode)
    Exit For
    End If
    Next
    curDeviceClass.Devices.Display(curDeviceClass, tvwDeviceClassNode)
    End If
    Next
    tvwTreeView.Sort()
    tvwRootNode.Expand()
    tvwTreeView.EndUpdate()

    End Sub

    Here's the code to display the devices for a given device class:

    Public Sub Display(ByRef curDeviceClass As DeviceClass, ByRef tvwDeviceClassNode As TreeNode)

    Dim tvwDeviceNode As New TreeNode

    For Each curDevice As Device In curDeviceClass.Devices
    If curDevice.Visible Then
    tvwDeviceNode = New TreeNode
    With tvwDeviceNode
    .ImageKey = curDeviceClass.Description
    .SelectedImageKey = curDeviceClass.Description
    .Text = curDevice.FriendlyName
    .Name = "[Device][" & curDevice.FriendlyName & "]"
    .Tag = curDevice.FriendlyName
    End With
    tvwDeviceClassNode.Nodes.Add(tvwDeviceNode)
    End If
    Next

    End Sub


    Let me know if you need to see more of the code. I'd rather not post the whole project here on the site but I realize that you might need to see the whole project in working order to assist me.

  4. #4
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,891

    Arrow Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    What happens (contrarily) when you call CM_Get_DevNode_Status on a non-pnp device?
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow threads, so if you have a secondary question, message me.

  5. #5
    Join Date
    Feb 2012
    Posts
    9

    Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    Nothing happens... All Non PNP Devices as well as the Non PNP Class are still visible in my device tree. Only the PNP devices seem to be affected. If you goto Device Manager and click Show hidden devices under the view menu you'll see an new device class appear in the device tree, Non Plug and Play Devices. Under that node you'll see a bunch, and I do mean a bunch, of Non PNP devices. If you goto your Network Adapters node you'll probably see several new devices as well. You may also see another device class, Storage Volumes and it's related devices. At least this is what I see on my machice. My existing API call successfully detects that those devices have been marked as hidden and does not add them to my device tree. The Non PNP Class and it's devices are left unaffected. Hence the reason for my question. Device Manager hides this device class and it's devices somehow and I'm trying to duplicate this in my application.

  6. #6
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,891

    Arrow Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    Ok, so you don't have a problem with non-pnp devices, you just don't have the NO_SHOW_IN_DM flag available...

    Like I mentioned before, just hide devices with the "LegacyDriver" flag on. Using the pnp config manager apis, you would just check for the following flag:
    DN_LEGACY_DRIVER &H1000

    If the device has this flag set, then you would exclude it from your list. You would check it exactly the same way you check for the NO_SHOW_IN_DM flag.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow threads, so if you have a secondary question, message me.

  7. #7
    Join Date
    Feb 2012
    Posts
    9

    Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    Thanks for the help. Sorry for the late reply, but I only now became aware of your reply. I didn't get notified of your reply. Your reply to my post came up in a internet search for information on another issue. It seems that my enum list is incomplete so I'll have to locate the full list and incorporate it into my project. I do appreciate your help. I'll let you know how things go after I have things updated and add this check into my code. Thanks again

  8. #8
    Join Date
    Feb 2012
    Posts
    9

    Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    I've been looking at some of the flag settings online and it seems that DN_LEGACY_DRIVER &H1000 is now called MOVED is this right? Here's my enum if this helps at all.

    Public Enum DeviceInstanceFlags As Integer
    ROOT_ENUMERATED = &H1
    DRIVER_LOADED = &H2
    ENUM_LOADED = &H4
    STARTED = &H8
    MANUAL = &H10
    NEED_TO_ENUM = &H20
    NOT_FIRST_TIME = &H40
    HARDWARE_ENUM = &H80
    LIAR = &H100
    HAS_MARK = &H200
    HAS_PROBLEM = &H400
    FILTERED = &H800
    MOVED = &H1000
    DISABLEABLE = &H2000
    REMOVABLE = &H4000
    PRIVATE_PROBLEM = &H8000
    MF_PARENT = &H10000
    MF_CHILD = &H20000
    WILL_BE_REMOVED = &H40000
    NOT_FIRST_TIMEE = &H80000
    STOP_FREE_RES = &H100000
    REBAL_CANDIDATE = &H200000
    BAD_PARTIAL = &H400000
    NT_ENUMERATOR = &H800000
    NT_DRIVER = &H1000000
    NEEDS_LOCKING = &H2000000
    ARM_WAKEUP = &H4000000
    APM_ENUMERATOR = &H8000000
    APM_DRIVER = &H10000000
    SILENT_INSTALL = &H20000000
    NO_SHOW_IN_DM = &H40000000
    End Enum

  9. #9
    Join Date
    Mar 2014
    Posts
    1

    Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    hi, VSCurtis

    i have the same requirement.did u solve that problem...? but i am doing it in c#

  10. #10
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,092

    Re: VB.Net 2010 API To Hide Non Plug and Play Devices In Device Manager

    Three things :

    1) Welcome to the Forums
    2) This thread is 2 years old
    3) This is the VB.NET Forum, not C#

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center