Results 1 to 3 of 3

Thread: access to target path of a shortcut [resolved]

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    5

    Question access to target path of a shortcut [resolved]

    I have researched all over the web and have yet to find a solution to my problem. If I have a shortcut file with .lnk extension in vb.net, how can I then locate the target path of that shortcut? I have seen this same question asked in the vb general questions regarding vb6 and there were no responses there.

    My current application:
    I populate a filelistbox with the desktop shortcut files- now I would like to find the path of each of the *.exe files that the .lnk file targets. Any ideas?
    Last edited by marq; Jan 6th, 2004 at 02:19 PM.

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    Add a multiline textbox to Form1 and copy the following code. You'll need to modify it to point to your desktop rather than mine.

    You also will need to add a reference to Windows Script Host Model.


    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         'Add a reference to "Windows Script Host Model"
    4.  
    5.         Dim fs As String = Dir("C:\Documents and Settings\tuglow\Desktop\*.lnk")
    6.         Dim txtStr As String = ""
    7.  
    8.         While fs <> ""
    9.             Dim str As String = "C:\Documents and Settings\tuglow\Desktop\" & fs
    10.  
    11.             Dim wShell As New IWshRuntimeLibrary.WshShell()
    12.             Dim shrt As IWshRuntimeLibrary.IWshShortcut
    13.  
    14.             shrt = wShell.CreateShortcut(str)
    15.  
    16.             txtStr &= shrt.TargetPath & vbCrLf
    17.  
    18.             fs = Dir()
    19.         End While
    20.  
    21.         TextBox1.Multiline = True
    22.         TextBox1.Text = txtStr
    23.  
    24.     End Sub
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    5

    thanks Tris- works like a charm! I can see that the main problem I had, I didn't know how to use the WSH in vb.net. After seeing your solution I found a good reference for adding WSH to vb.net.
    Here is a link to that page-
    http://msdn.microsoft.com/library/de...et07232002.asp

Posting Permissions

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



Click Here to Expand Forum to Full Width