none
Operation with devices RRS feed

  • Question

  • Good…
    Firstly, I tell you.
    The following code allows me to list as:

    Dim SH As New Shell32.Shell
    
            Dim drives As Shell32.Folder = SH.NameSpace(Shell32.ShellSpecialFolderConstants.ssfDRIVES)
    
            For Each Item As Shell32.FolderItem In drives.Items
                    MsgBox(Item.Name)
            Next Item
    

    1.- Local units, C, D
    2.- DVD / CD reading units
    3.- The pendrives, portable (USB) connected to Windows
    4.- Mobile devices (Android) connected to Windows
    And others…

    Now, the operation I want to perform is:
    Block, that is, not shown in the list
    1.- Local units, C, D
    2.- DVD / CD reading units

    And the last two I would like to show
    3.- The pendrives, portable (USB) connected to Windows
    4.- Mobile devices (Android) connected to Windows

    Try to solve this problem with this condition

    If Item.IsFileSystem = False Then
                    MsgBox(Item.Name)
                End If
    

    But it just showed me, the connected mobile devices and not the pendrives.

    I hope you can help me with this.

    thanks

    Wednesday, December 11, 2019 12:09 AM

Answers

  • Hi,

    Did you resolve the issue?

    If you have resolved the issue then pleasse mark the post or posts that helped you as The Answer using the Mark as Answer link at the bottom of the post.

    Marking answers will help other community members find solutions in the future.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JenCarlos Wednesday, December 25, 2019 7:44 PM
    Thursday, December 12, 2019 6:04 AM
    Moderator

All replies

  • Hi,

    I don't use this method from you, I use the Win32_USBHub class by adding a reference to System.Management dll. You can have a try.

    Imports System.Management
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim devices As New List(Of String)
            Dim collection As ManagementObjectCollection
            Using searcher = New ManagementObjectSearcher("Select * From Win32_USBHub")
                collection = searcher.Get()
            End Using
    
            For Each device In collection
                devices.Add(CStr(device.GetPropertyValue("DeviceID"))) 'You can also change it into other properties
            Next
    
            collection.Dispose()
    
            Dim i As Integer = 0
            For Each usbDevice In devices
                i += 1
                ListBox1.Items.Add(String.Format("{0}.usbDevice name: {1}", i, usbDevice))
            Next
        End Sub
    End Class

    Someone has asked similar questions, you can also refer to:

    https://stackoverflow.com/questions/6003822/how-to-detect-a-usb-drive-has-been-plugged-in

    https://stackoverflow.com/questions/3331043/get-list-of-connected-usb-devices

    Hope it be helpful.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 11, 2019 5:12 AM
    Moderator
  • Thank you very much for the reply...

    Julie Xu-MSFT

    Thursday, December 12, 2019 2:15 AM
  • Hi,

    Did you resolve the issue?

    If you have resolved the issue then pleasse mark the post or posts that helped you as The Answer using the Mark as Answer link at the bottom of the post.

    Marking answers will help other community members find solutions in the future.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JenCarlos Wednesday, December 25, 2019 7:44 PM
    Thursday, December 12, 2019 6:04 AM
    Moderator