bjay55 Posted May 17, 2006 Posted May 17, 2006 Using visual basic .net, I was wondering how I would be able to get the target file of a shortcut (.lnk file). Thank you for any help. Quote
nbrege Posted May 17, 2006 Posted May 17, 2006 I was just wondering the same thing. Also, is it possible to change the target of a shortcut or create a new shortcut? I hope someone can answer this... Quote
mskeel Posted May 17, 2006 Posted May 17, 2006 Shortcuts are in a binary format and, unlike the Linux ln command, there is no way that I have been able to find for creating, manipulating, or dealing with shortcuts on the command line or in a program. The last time I messed with this stuff, about 2 years ago, I found a command line tool online that would do everything I wanted -- reading, creating, deciphering, etc. Of course, now that I think about it, I was writing in Perl at the time so I'm not sure if there are facilities in .Net that will help you or not. But I do know there are free tools out there. Try an internet search and see what turns up. The tool I found was called shortcut.exe and it was made by Optimum X. Hopefully that will help. And there may be a .Net way to do it too; I'm just not sure off the top of my head. Quote
bjay55 Posted May 17, 2006 Author Posted May 17, 2006 Found Something That Works I found something that works for getting the link target and description. I found the function GetLinkInfo, it is in the sheltarg.dll file. Private Function GetLinkTarget(ByVal filename As String) As String Dim ret As Integer Dim path, description As String path = Space$(256) description = Space$(256) ret = GetLinkInfo(Me.Handle, filename, path, description) GetLinkTarget = path End Function Thanks for all your replies. Quote
Wraith Posted May 18, 2006 Posted May 18, 2006 If you're not averse to a little COM pinvoke you can just declare the IShellLink interface, ShellLink coclass and the associated bits and pieces (Win32FindData struct a few enumerations and various other things). Then wrap the IShellLink in a disposable object and you've something that'll let you deal with shortcuts easily. Quote
nbrege Posted May 18, 2006 Posted May 18, 2006 (edited) This seems to be the easiest way so far. It lets you read all the attributes of a shortcut as well as change them or create a new shortcut from scratch. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim WshShell As Object, Shortcut As Object WshShell = CreateObject("WScript.Shell") Shortcut = WshShell.CreateShortcut("c:\\Shortcut Test.lnk") MessageBox.Show(Shortcut.targetpath) End Sub This code should run as-is... Edited May 18, 2006 by nbrege Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.