Hi this is a small bit of code I made to get the exe path and file from a shortcut, it may need tidying up a bit but I try it on a few shortcuts and seems to work
anyway comments and suggestions welcome.
vbnet Code:
Imports System.IO
Imports System.Text
Public Class Form1
Public Function GetShortCutLink(ByVal Source As String) As String
Dim br As BinaryReader
Dim Bytes(2048) As Byte
Dim sb As New StringBuilder()
If Not File.
Exists(Source
) Then Throw New FileNotFoundException
End If
'Open shortcut file for reading.
br =
New BinaryReader
(File.
OpenRead(Source
), Encoding.
ASCII) 'Read 2048 bytes into bytes array.
Bytes = br.ReadBytes(Bytes.Length)
br.Close()
For Counter As Integer = 100 To Bytes.Length - 1
'Check for :\ and
If Bytes(Counter) = 58 And Bytes(Counter + 1) = 92 And Bytes(Counter - 2) <> 47 Then
Counter = (Counter - 1)
Do Until Bytes(Counter) = 0
'Build string.
sb.Append(Chr(Bytes(Counter)))
'INC Counter
Counter += 1
Loop
Exit For
End If
Next Counter
'Return shortcut link.
Return sb.ToString()
End Function
Private Sub cmdGetLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetLink.Click
Try
'Try and get link.
Dim sLink As String = GetShortCutLink("C:\out\data\Easy GIF Animator Pro 5.2.lnk")
MessageBox.Show(sLink, "Link",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
End Class