none
How to get the display name of lnk file RRS feed

Answers

  • Hi gaxjyxq,

    You can try this code.

    Public Shared Function GetLnkTarget(lnkPath As String) As String
            Dim shl = New Shell32.Shell()
            ' Move this to class scope
            lnkPath = System.IO.Path.GetFullPath(lnkPath)
            Dim dir = shl.[NameSpace](System.IO.Path.GetDirectoryName(lnkPath))
            Dim itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath))
            'Dim lnk = DirectCast(itm.GetLink, Shell32.ShellLinkObject)
            Return itm
        End Function

    Best Regards,

    Cherry


    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 gaxjyxq Tuesday, May 16, 2017 10:07 PM
    Tuesday, May 16, 2017 9:57 AM
    Moderator

All replies

  • I found the link below to get link file information using the MSjogren.Samples.ShellLink

    https://social.msdn.microsoft.com/Forums/en-US/654cba45-bd30-4a23-b2c4-1a46d59b31fc/how-to-create-a-shotcut-lnk-programatically-vb-2005?forum=vblanguage

    But how to get display name of lnk file? not the file name.

    In Windows 10 creator, open the folder (C:\Users\UserName\AppData\Local\Microsoft\Windows\WinX), some lnk files show friendly name but not the file name.

    Wednesday, May 10, 2017 9:48 PM
  •  Unless windows 8 or 10 have some new property for shortcuts,  i have never seen a "Display Name" property for a (.lnk) type shortcut.  Can you show an example image that shows what "Display Name" you are referring to?

     According to my testing on Win 7,  i only see these properties for (.lnk) shortcuts that can be retrieved....

    Imports IWshRuntimeLibrary 'Add a Reference to (Windows Scripting Host Object Model) in the (Com) tab of the (Add Reference) dialog window for this Namespace.
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim FileName As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "My Lnk Shortcut.lnk")
    
            Dim sb As New System.Text.StringBuilder
    
            Dim theShell As New WshShell
            Dim theShortcut As WshShortcut = CType(theShell.CreateShortcut(FileName), WshShortcut)
    
            sb.AppendLine("Arguments:  " & theShortcut.Arguments)
            sb.AppendLine("Description:  " & theShortcut.Description)
            sb.AppendLine("FullName:  " & theShortcut.FullName)
            sb.AppendLine("Hotkey:  " & theShortcut.Hotkey.ToString)
            sb.AppendLine("IconLocation:  " & theShortcut.IconLocation)
            sb.AppendLine("TargetPath:  " & theShortcut.TargetPath)
            sb.AppendLine("WindowStyle:  " & theShortcut.WindowStyle.ToString)
            sb.AppendLine("WorkingDirectory:  " & theShortcut.WorkingDirectory)
    
            Label1.Text = sb.ToString
        End Sub
    
    End Class
    
     

     


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

    Wednesday, May 10, 2017 9:54 PM
  • I'm replying only because I posted the VB.NET version. Wish I could tell you why but I'm running Windows 7.

    What I used was is shown below taken out of a larger class which did a for/loop where each file was passed in the function below.

    Private Function IsCorrectShortCut(ByVal FileName As String) As Boolean
    
       Try
          Using Shortcut As ShellShortcut = New ShellShortcut(FileName)
             If Shortcut.Path.ToLower = AppPathFileName().ToLower Then
                Return True
             Else
                Return False
             End If
          End Using
       Catch ex As Exception
          Return False
       End Try
    
    End Function
    

    AppPathFileName is the name of my executable whixh is not important.

    ''' <summary>
    ''' Provides application path along with application executing assembly (executable name)
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function AppPathFileName() As String
       Return System.Reflection.Assembly.GetExecutingAssembly.Location()
    End Function


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, May 10, 2017 10:13 PM
    Moderator
  • The lnk file name is "06-SystemAbout.lnk", the display name is "系统".

    There is the "Name" property in the Shell32.Shell, it can get the right display name of lnk file.

     Dim shell As New Shell32.Shell

            Dim ShortcutDirectory As String = IO.Path.GetDirectoryName(txtShortcut.Text)
            Dim ShortcutFileName As String = IO.Path.GetFileName(txtShortcut.Text)

            Dim shortcut_folder As Shell32.Folder = shell.NameSpace(ShortcutDirectory)

            Dim folder_item As Shell32.FolderItem = shortcut_folder.Items.Item(ShortcutFileName)

            Dim lnk As Shell32.ShellLinkObject = CType(folder_item.GetLink, Shell32.ShellLinkObject)
            txtName.Text = folder_item.Name

    But i want to use MSjogren.Samples.ShellLink.VB class to get display name in the link below, but there is no the "Name" property in the class.

    https://social.msdn.microsoft.com/Forums/en-US/654cba45-bd30-4a23-b2c4-1a46d59b31fc/how-to-create-a-shotcut-lnk-programatically-vb-2005?forum=vblanguage




    • Edited by gaxjyxq Wednesday, May 10, 2017 11:16 PM
    Wednesday, May 10, 2017 11:04 PM
  • I feel i need to use the shell32.shell to get the display name, thank you.
    Thursday, May 11, 2017 12:42 AM
  • Hi gaxjyxq,

    You can try this code.

    Public Shared Function GetLnkTarget(lnkPath As String) As String
            Dim shl = New Shell32.Shell()
            ' Move this to class scope
            lnkPath = System.IO.Path.GetFullPath(lnkPath)
            Dim dir = shl.[NameSpace](System.IO.Path.GetDirectoryName(lnkPath))
            Dim itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath))
            'Dim lnk = DirectCast(itm.GetLink, Shell32.ShellLinkObject)
            Return itm
        End Function

    Best Regards,

    Cherry


    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 gaxjyxq Tuesday, May 16, 2017 10:07 PM
    Tuesday, May 16, 2017 9:57 AM
    Moderator
  • Can Shell32.Shell get icon path and icon index for the shell item? thank you.
    Thursday, May 18, 2017 10:37 AM
  • Hi gaxjyxq,

    I find one sample that may be helpful to you, it is C# sample, but you can use any Convert tool to convert VB.

    https://www.codeproject.com/articles/2532/obtaining-and-managing-file-and-folder-icons-using

    Hope it is helpful to you.

    Best Regards,

    Cherry


    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.

    Friday, May 19, 2017 7:20 AM
    Moderator
  • Yes, i known this way, the shell32.shell can not get the icon, is it?
    Friday, May 19, 2017 11:15 AM