[RESOLVED] vb 2010 Shortcut path extraction from dropping .lnk onto form
I have searched and browsed and read a considerable number of posts here, but i must have some kind of mental block. I can't find what i'm looking for.. So I'd be grateful for some syntax help.
Scenario:
I am attempting to perform some work on files (rename/delete) in folder, usually in a network location. Because the location of products folder is not critical, it's rarely ever in the same place on different networks. A simple shortcut on the client machine is all that's required from the client perspective and the rest of the product is self contained on the server somewhere.
To run the 'fix' my small application will perform quickly and easily, I need to parse the path held in the target box of the .lnk. Then perform ifexists for a specific file and then do my renaming/deleting.
To keep it as simple as possible, the end user should just 'drop' the shortcut onto my form then click 'fix'.
The problem:
How in the heavens can I retrieve the target location from the .lnk into a string without windows scripting host?
Note:
I'm aware there may be UAC issues, and other network security issues and and prviliges required and all sorts. I'll ask about those when I need to :-)
Thanks for your syntax!
Rob
Re: vb 2010 Shortcut path extraction from dropping .lnk onto form
There is no method in the .NET Framework for obtaining the target path. I do have code (requres a fair amount of code that works) found at the following link. Be forewarned it is not easy to read and follow unless you spend time with it.
http://social.msdn.microsoft.com/For...4-1a46d59b31fc
Here is the part to get the target path in the Console.WriteLine. It is possible that an empty target path may be returned so you need to check for this
Code:
Private Function IsCorrectShortCut(ByVal FileName As String) As Boolean
Try
Using Shortcut As ShellShortcut = New ShellShortcut(FileName)
Console.WriteLine("[{0}]", Shortcut.WorkingDirectory)
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
Re: vb 2010 Shortcut path extraction from dropping .lnk onto form
Quote:
Originally Posted by
kevininstructor
There is no method in the .NET Framework for obtaining the target path. I do have code (requres a fair amount of code that works) found at the following link. Be forewarned it is not easy to read and follow unless you spend time with it.
http://social.msdn.microsoft.com/For...4-1a46d59b31fc
Here is the part to get the target path in the Console.WriteLine. It is possible that an empty target path may be returned so you need to check for this
Code:
Private Function IsCorrectShortCut(ByVal FileName As String) As Boolean
Try
Using Shortcut As ShellShortcut = New ShellShortcut(FileName)
Console.WriteLine("[{0}]", Shortcut.WorkingDirectory)
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
Thank you for your fast reply Kevin! I have spent quite a lot of time with this problem already. I then got a headache and had to go for a walk...
Anyway, I'll read over the link and the code you provided right now.
I'll post here when I get it to work how I need it. As I'm more likely to ask another question related to that code, I won't mark it as solved just yet if that's ok?
Rob
Re: vb 2010 Shortcut path extraction from dropping .lnk onto form
nope. not working for my personal requirements. but thanks. :0)
Closing this post as i'm sure it's not possible just yet and i've not got the interest in it anymore.