Windows 10 menu item paths

  • Thread starter Thread starter _Gabriel_
  • Start date Start date
G

_Gabriel_

Guest
Im still having trouble trying to get information from the Start menu items in Windows 10. My goal is the following, drag any item to my application, then it gets the fullpath, from there get some more information, for example, the display name, icon, ...

There are no problems when I drag items from desktop or Windows Explorer, some examples:

- todo.txt file on the desktop (physical address)
fullpath = "C:\Users\Gabriel\Desktop\todo.txt"

- My PC folder (virtual address)
fullpath = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"

With these values I get the info I want with no issues. However, the situation changes completely when dragging items from the start menu, some examples:

- STEAM
fullpath = "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}\Steam\Steam.exe"

- VISUAL STUDIO 2013
fullpath = "VisualStudio.12.0"

- CALENDAR
fullpath = "microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.calendar"

Apparently these values have no practical use, because I can not get any information with them.

For example, the code detailed below returns the display name of any physical or virtual path, but when I use any start menu address I get System.IO.FileNotFoundException error. What can I do?


Imports System.Runtime.InteropServices

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim info As New itemINFO

Dim display1 As String = info.GetDisplayName("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", Me) <-- OK
MessageBox.Show(Me, display1)

Dim display2 As String = info.GetDisplayName("microsoft.windowscommunicationsapps_8wekyb3d8bbwe!microsoft.windowslive.calendar", Me) <-- FileNotFoundException
End Sub
End Class

Public Class itemINFO

Public Function GetDisplayName(fullpath As String, parent As Form) As String
Dim result As String = ""

Dim shellitem As IShellItem = CreateItemFromParsingName(fullpath, parent)

If shellitem IsNot Nothing Then
Dim resultPtr As IntPtr
shellitem.GetDisplayName(SIGDN.NORMALDISPLAY, resultPtr)
result = Marshal.PtrToStringUni(resultPtr)
Marshal.FreeCoTaskMem(resultPtr)
End If

Return result
End Function

Private Shared Function CreateItemFromParsingName(path As String, parent As Form) As IShellItem
Dim ****em As IShellItem = Nothing

Try
SHCreateItemFromParsingName(path, IntPtr.Zero, GetType(IShellItem).GUID, ****em)
Catch ex As System.Exception
MessageBox.Show(parent, ex.ToString)
End Try

Return ****em
End Function

<DllImport("shell32.dll", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
Public Shared Sub SHCreateItemFromParsingName( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal pszPath As String, _
ByVal pbc As IntPtr, _
<MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid, _
<MarshalAs(UnmanagedType.Interface, IidParameterIndex:=2)> ByRef ppv As IShellItem)
End Sub

<ComImport()> _
<Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")> _
<InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IShellItem
Sub BindToHandler(ByVal pbc As IntPtr, _
<MarshalAs(UnmanagedType.LPStruct)> ByVal bhid As Guid, _
<MarshalAs(UnmanagedType.LPStruct)> ByVal riid As Guid, _
ByRef ppv As IntPtr)

Sub GetParent(ByRef ppsi As IShellItem)

Sub GetDisplayName(ByVal sigdnName As SIGDN, ByRef ppszName As IntPtr)

Sub GetAttributes(ByVal sfgaoMask As UInt32, ByRef psfgaoAttribs As UInt32)

Sub Compare(ByVal psi As IShellItem, ByVal hint As UInt32, ByRef piOrder As Integer)
End Interface

Public Enum SIGDN As UInteger
NORMALDISPLAY = 0
PARENTRELATIVEPARSING = &H80018001UI
PARENTRELATIVEFORADDRESSBAR = &H8001C001UI
DESKTOPABSOLUTEPARSING = &H80028000UI
PARENTRELATIVEEDITING = &H80031001UI
DESKTOPABSOLUTEEDITING = &H8004C000UI
FILESYSPATH = &H80058000UI
URL = &H80068000UI
End Enum

End Class

Continue reading...
 
Back
Top