none
Devices RRS feed

  • Question

  • Good ...

    Is there any Guid that allows me to get portable devices, connected to the computer, as in the windows explorer?

    I have the necessary apis ... as much as iShellFolder ... IEnumIdList, but I lack the proper Guid to do this operation ...

    Please, someone could give me the correct Guid ...

    Thanks

    Wednesday, April 24, 2019 5:17 PM

Answers

  • I have let "c:\" for test : replace it by the WPD Guid by uncommenting the line
    and comment the flag 'EXPLORER_BROWSER_OPTIONS.EBO_SHOWFRAMES' to remove panels :

    Dim pExplorerBrowser As IExplorerBrowser = Nothing
    Dim pFolderViewPtr As IntPtr = IntPtr.Zero
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ClientSize = New System.Drawing.Size(980, 500)
        Name = "Form1"
        Text = "Test IExplorerBrowser"
        CenterToScreen()
    
        Dim CLSID_ExplorerBrowser As New Guid("71f96385-ddd6-48d3-a0c1-ae06e8b055fb")
        Dim ExplorerBrowserType As Type = Type.GetTypeFromCLSID(CLSID_ExplorerBrowser, True)
        Dim ExplorerBrowser As Object = Activator.CreateInstance(ExplorerBrowserType)
        pExplorerBrowser = DirectCast(ExplorerBrowser, IExplorerBrowser)
    
        Dim rc As RECT
        GetClientRect(Me.Handle, rc)
        InflateRect(rc, -10, -10)
        Dim hr As HRESULT = pExplorerBrowser.Initialize(Me.Handle, rc, Nothing)
        If (hr = HRESULT.S_OK) Then
            pExplorerBrowser.SetOptions(EXPLORER_BROWSER_OPTIONS.EBO_SHOWFRAMES Or
                EXPLORER_BROWSER_OPTIONS.EBO_ALWAYSNAVIGATE Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOTRAVELLOG Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOWRAPPERWINDOW Or
                EXPLORER_BROWSER_OPTIONS.EBO_HTMLSHAREPOINTVIEW Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOBORDER Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOPERSISTVIEWSTATE)
            Dim pidlFull As IntPtr = IntPtr.Zero
            hr = SHILCreateFromPath("C:\", pidlFull, Nothing)
            ' WPD
            'hr = SHILCreateFromPath("shell:::{35786D3C-B075-49b9-88DD-029876E11C01}", pidlFull, Nothing)
            If (hr = HRESULT.S_OK) Then
                pExplorerBrowser.BrowseToIDList(pidlFull, SBSP_ABSOLUTE)
            End If
        End If
    End Sub
    
    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Dim hWndBrowserControl As IntPtr = FindWindowEx(Me.Handle, IntPtr.Zero, "ExplorerBrowserControl", Nothing)
        If (hWndBrowserControl <> IntPtr.Zero) Then
            MoveWindow(hWndBrowserControl, 10, 10, Me.ClientSize.Width - 10 * 2, Me.ClientSize.Height - 10 * 2, True)
        End If
    End Sub

    Declarations :

        Public Enum HRESULT As Integer
            S_OK = 0
            S_FALSE = 1
            E_NOINTERFACE = &H80004002
            E_NOTIMPL = &H80004001
            E_FAIL = &H80004005
            E_UNEXPECTED = &H8000FFFF
        End Enum
    
        <ComImport>
        <Guid("dfd3b6b5-c10c-4be9-85f6-a66969f402f6")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IExplorerBrowser
            Function Initialize(hwndParent As IntPtr, ByRef prc As RECT, ByRef pfs As FOLDERSETTINGS) As HRESULT
            Function Destroy() As HRESULT
            Function SetRect(phdwp As IntPtr, rcBrowser As RECT) As HRESULT
            Function SetPropertyBag(pszPropertyBag As String) As HRESULT
            Function SetEmptyText(pszEmptyText As String) As HRESULT
            Function SetFolderSettings(ByRef pfs As FOLDERSETTINGS) As HRESULT
    
            'IExplorerBrowserEvents *psbe
            Function Advise(psbe As IntPtr, ByRef pdwCookie As Integer) As HRESULT
            Function Unadvise(dwCookie As Integer) As HRESULT
            Function SetOptions(dwFlag As EXPLORER_BROWSER_OPTIONS) As HRESULT
            Function GetOptions(ByRef pdwFlag As EXPLORER_BROWSER_OPTIONS) As HRESULT
            Function BrowseToIDList(pidl As IntPtr, uFlags As UInteger) As HRESULT
    
            'IUnknown *punk,
            Function BrowseToObject(punk As IntPtr, uFlags As UInteger) As HRESULT
            Function FillFromObject(punk As IntPtr, dwFlags As EXPLORER_BROWSER_FILL_FLAGS) As HRESULT
            Function RemoveAll() As HRESULT
            Function GetCurrentView(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
        End Interface
    
        Public Const SBSP_ABSOLUTE = &H0
    
        Public Enum EXPLORER_BROWSER_OPTIONS As Integer
            EBO_NONE = 0
            EBO_NAVIGATEONCE = &H1
            EBO_SHOWFRAMES = &H2
            EBO_ALWAYSNAVIGATE = &H4
            EBO_NOTRAVELLOG = &H8
            EBO_NOWRAPPERWINDOW = &H10
            EBO_HTMLSHAREPOINTVIEW = &H20
            EBO_NOBORDER = &H40
            EBO_NOPERSISTVIEWSTATE = &H80
        End Enum
    
        Public Enum EXPLORER_BROWSER_FILL_FLAGS As Integer
            EBF_NONE = 0
            EBF_SELECTFROMDATAOBJECT = &H100
            EBF_NODROPTARGET = &H200
        End Enum
    
        Public Enum FOLDERVIEWMODE As Integer
            FVM_AUTO = -1
            FVM_FIRST = 1
            FVM_ICON = 1
            FVM_SMALLICON = 2
            FVM_LIST = 3
            FVM_DETAILS = 4
            FVM_THUMBNAIL = 5
            FVM_TILE = 6
            FVM_THUMBSTRIP = 7
            FVM_CONTENT = 8
            FVM_LAST = 8
        End Enum
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure FOLDERSETTINGS
            Public ViewMode As Integer
            Public fFlags As UInteger
        End Structure
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
            Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)
                Me.left = left
                Me.top = top
                Me.right = right
                Me.bottom = bottom
            End Sub
        End Structure
    
        <DllImport("User32.dll", SetLastError:=True)>
        Private Shared Function MoveWindow(hWnd As IntPtr, X As Integer, Y As Integer, nWidth As Integer, nHeight As Integer, bRepaint As Boolean) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function FindWindowEx(ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function GetClientRect(hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function OffsetRect(ByRef lprc As RECT, dx As Integer, dy As Integer) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function InflateRect(ByRef lprc As RECT, dx As Integer, dy As Integer) As Boolean
        End Function
    
        <DllImport("Shell32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)>
        Public Shared Function SHILCreateFromPath(<MarshalAs(UnmanagedType.LPWStr)> pszPath As String, ByRef ppIdl As IntPtr, ByRef rgflnOut As UInteger) As HRESULT
        End Function

    • Edited by Castorix31 Saturday, April 27, 2019 3:07 PM
    • Marked as answer by JenCarlos Saturday, April 27, 2019 4:58 PM
    Saturday, April 27, 2019 7:28 AM

All replies

  • Windows Portable Devices (WPD)
    Class = WPD
    ClassGuid = {eec5ad98-8080-425f-922a-dabf3de3f69a}
    (Windows Vista and later versions of Windows) This class includes WPD devices.

    from System-Defined Device Setup Classes Available to Vendors

    or from SDK

    DEFINE_GUID( GUID_DEVCLASS_WPD,                 0xeec5ad98L, 0x8080, 0x425f, 0x92, 0x2a, 0xda, 0xbf, 0x3d, 0xe3, 0xf6, 0x9a );

    • Edited by Castorix31 Wednesday, April 24, 2019 5:35 PM
    Wednesday, April 24, 2019 5:34 PM
  • If I use this Guid, it will not give me the results as from the windows explorer, the icons, for example, it also seems to me another issue, this one with different apis ...

    Is not there a Guid to use with IShellFolder?

    Wednesday, April 24, 2019 6:11 PM
  • For the Shell, it is {35786D3C-B075-49b9-88DD-029876E11C01}

    (shell:::{35786D3C-B075-49b9-88DD-029876E11C01})
    • Edited by Castorix31 Wednesday, April 24, 2019 6:36 PM
    • Proposed as answer by phil chelis Thursday, April 25, 2019 9:55 AM
    Wednesday, April 24, 2019 6:20 PM
  • The Guid works, but when I connect a usb (pendrive), it does not show me the icon as in the windows explorer, rather it looks like the device manager. There will not be another Guid shell more effective? Please
    Friday, April 26, 2019 12:40 PM
  • I connected my phone and I get same window and icon as Explorer with this Guid :

    Friday, April 26, 2019 1:57 PM
  • If it works with a mobile phone, I did the test. But with a usb (pendrive) of 8 GB, the same thing does not happen, it fails.
    Friday, April 26, 2019 4:24 PM
  • I don't see how it can fail with Shell interfaces like IExplorerBrowser, as it is what Explorer uses...
    • Edited by Castorix31 Friday, April 26, 2019 4:29 PM
    Friday, April 26, 2019 4:29 PM
  • I'm not using IExplorerBrowser, or maybe, that fails. Please, you can give me the example ...
    Friday, April 26, 2019 7:01 PM
  • I have let "c:\" for test : replace it by the WPD Guid by uncommenting the line
    and comment the flag 'EXPLORER_BROWSER_OPTIONS.EBO_SHOWFRAMES' to remove panels :

    Dim pExplorerBrowser As IExplorerBrowser = Nothing
    Dim pFolderViewPtr As IntPtr = IntPtr.Zero
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ClientSize = New System.Drawing.Size(980, 500)
        Name = "Form1"
        Text = "Test IExplorerBrowser"
        CenterToScreen()
    
        Dim CLSID_ExplorerBrowser As New Guid("71f96385-ddd6-48d3-a0c1-ae06e8b055fb")
        Dim ExplorerBrowserType As Type = Type.GetTypeFromCLSID(CLSID_ExplorerBrowser, True)
        Dim ExplorerBrowser As Object = Activator.CreateInstance(ExplorerBrowserType)
        pExplorerBrowser = DirectCast(ExplorerBrowser, IExplorerBrowser)
    
        Dim rc As RECT
        GetClientRect(Me.Handle, rc)
        InflateRect(rc, -10, -10)
        Dim hr As HRESULT = pExplorerBrowser.Initialize(Me.Handle, rc, Nothing)
        If (hr = HRESULT.S_OK) Then
            pExplorerBrowser.SetOptions(EXPLORER_BROWSER_OPTIONS.EBO_SHOWFRAMES Or
                EXPLORER_BROWSER_OPTIONS.EBO_ALWAYSNAVIGATE Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOTRAVELLOG Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOWRAPPERWINDOW Or
                EXPLORER_BROWSER_OPTIONS.EBO_HTMLSHAREPOINTVIEW Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOBORDER Or
                EXPLORER_BROWSER_OPTIONS.EBO_NOPERSISTVIEWSTATE)
            Dim pidlFull As IntPtr = IntPtr.Zero
            hr = SHILCreateFromPath("C:\", pidlFull, Nothing)
            ' WPD
            'hr = SHILCreateFromPath("shell:::{35786D3C-B075-49b9-88DD-029876E11C01}", pidlFull, Nothing)
            If (hr = HRESULT.S_OK) Then
                pExplorerBrowser.BrowseToIDList(pidlFull, SBSP_ABSOLUTE)
            End If
        End If
    End Sub
    
    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        Dim hWndBrowserControl As IntPtr = FindWindowEx(Me.Handle, IntPtr.Zero, "ExplorerBrowserControl", Nothing)
        If (hWndBrowserControl <> IntPtr.Zero) Then
            MoveWindow(hWndBrowserControl, 10, 10, Me.ClientSize.Width - 10 * 2, Me.ClientSize.Height - 10 * 2, True)
        End If
    End Sub

    Declarations :

        Public Enum HRESULT As Integer
            S_OK = 0
            S_FALSE = 1
            E_NOINTERFACE = &H80004002
            E_NOTIMPL = &H80004001
            E_FAIL = &H80004005
            E_UNEXPECTED = &H8000FFFF
        End Enum
    
        <ComImport>
        <Guid("dfd3b6b5-c10c-4be9-85f6-a66969f402f6")>
        <InterfaceType(ComInterfaceType.InterfaceIsIUnknown)>
        Public Interface IExplorerBrowser
            Function Initialize(hwndParent As IntPtr, ByRef prc As RECT, ByRef pfs As FOLDERSETTINGS) As HRESULT
            Function Destroy() As HRESULT
            Function SetRect(phdwp As IntPtr, rcBrowser As RECT) As HRESULT
            Function SetPropertyBag(pszPropertyBag As String) As HRESULT
            Function SetEmptyText(pszEmptyText As String) As HRESULT
            Function SetFolderSettings(ByRef pfs As FOLDERSETTINGS) As HRESULT
    
            'IExplorerBrowserEvents *psbe
            Function Advise(psbe As IntPtr, ByRef pdwCookie As Integer) As HRESULT
            Function Unadvise(dwCookie As Integer) As HRESULT
            Function SetOptions(dwFlag As EXPLORER_BROWSER_OPTIONS) As HRESULT
            Function GetOptions(ByRef pdwFlag As EXPLORER_BROWSER_OPTIONS) As HRESULT
            Function BrowseToIDList(pidl As IntPtr, uFlags As UInteger) As HRESULT
    
            'IUnknown *punk,
            Function BrowseToObject(punk As IntPtr, uFlags As UInteger) As HRESULT
            Function FillFromObject(punk As IntPtr, dwFlags As EXPLORER_BROWSER_FILL_FLAGS) As HRESULT
            Function RemoveAll() As HRESULT
            Function GetCurrentView(ByRef riid As Guid, ByRef ppv As IntPtr) As HRESULT
        End Interface
    
        Public Const SBSP_ABSOLUTE = &H0
    
        Public Enum EXPLORER_BROWSER_OPTIONS As Integer
            EBO_NONE = 0
            EBO_NAVIGATEONCE = &H1
            EBO_SHOWFRAMES = &H2
            EBO_ALWAYSNAVIGATE = &H4
            EBO_NOTRAVELLOG = &H8
            EBO_NOWRAPPERWINDOW = &H10
            EBO_HTMLSHAREPOINTVIEW = &H20
            EBO_NOBORDER = &H40
            EBO_NOPERSISTVIEWSTATE = &H80
        End Enum
    
        Public Enum EXPLORER_BROWSER_FILL_FLAGS As Integer
            EBF_NONE = 0
            EBF_SELECTFROMDATAOBJECT = &H100
            EBF_NODROPTARGET = &H200
        End Enum
    
        Public Enum FOLDERVIEWMODE As Integer
            FVM_AUTO = -1
            FVM_FIRST = 1
            FVM_ICON = 1
            FVM_SMALLICON = 2
            FVM_LIST = 3
            FVM_DETAILS = 4
            FVM_THUMBNAIL = 5
            FVM_TILE = 6
            FVM_THUMBSTRIP = 7
            FVM_CONTENT = 8
            FVM_LAST = 8
        End Enum
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure FOLDERSETTINGS
            Public ViewMode As Integer
            Public fFlags As UInteger
        End Structure
    
        <StructLayout(LayoutKind.Sequential)>
        Public Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
            Public Sub New(left As Integer, top As Integer, right As Integer, bottom As Integer)
                Me.left = left
                Me.top = top
                Me.right = right
                Me.bottom = bottom
            End Sub
        End Structure
    
        <DllImport("User32.dll", SetLastError:=True)>
        Private Shared Function MoveWindow(hWnd As IntPtr, X As Integer, Y As Integer, nWidth As Integer, nHeight As Integer, bRepaint As Boolean) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
        Public Shared Function FindWindowEx(ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function GetClientRect(hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function OffsetRect(ByRef lprc As RECT, dx As Integer, dy As Integer) As Boolean
        End Function
    
        <DllImport("User32.dll", SetLastError:=True)>
        Public Shared Function InflateRect(ByRef lprc As RECT, dx As Integer, dy As Integer) As Boolean
        End Function
    
        <DllImport("Shell32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)>
        Public Shared Function SHILCreateFromPath(<MarshalAs(UnmanagedType.LPWStr)> pszPath As String, ByRef ppIdl As IntPtr, ByRef rgflnOut As UInteger) As HRESULT
        End Function

    • Edited by Castorix31 Saturday, April 27, 2019 3:07 PM
    • Marked as answer by JenCarlos Saturday, April 27, 2019 4:58 PM
    Saturday, April 27, 2019 7:28 AM
  • The code works very well.

    You are a genius, thank you very much.

    Saturday, April 27, 2019 4:58 PM