|
-
Jan 6th, 2004, 01:05 AM
#1
Thread Starter
New Member
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.
-
Jan 6th, 2004, 09:12 AM
#2
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Add a reference to "Windows Script Host Model"
Dim fs As String = Dir("C:\Documents and Settings\tuglow\Desktop\*.lnk")
Dim txtStr As String = ""
While fs <> ""
Dim str As String = "C:\Documents and Settings\tuglow\Desktop\" & fs
Dim wShell As New IWshRuntimeLibrary.WshShell()
Dim shrt As IWshRuntimeLibrary.IWshShortcut
shrt = wShell.CreateShortcut(str)
txtStr &= shrt.TargetPath & vbCrLf
fs = Dir()
End While
TextBox1.Multiline = True
TextBox1.Text = txtStr
End Sub
This world is not my home. I'm just passing through.
-
Jan 6th, 2004, 12:36 PM
#3
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|