-
Sep 24th, 2012, 03:20 PM
#1
Thread Starter
Fanatic Member
Get exe from shortcut no api or vbscript
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
-
Oct 7th, 2012, 04:13 PM
#2
Re: Get exe from shortcut no api or vbscript
Nice do you understand the rest of the stuff in a .lnk file then or is that the only bit you know how to parse at the moment? I'm just wondering if you'd be able to use this knowledge to write a .NET method that would create your own shortcut files, as that seems to be a real pain to do from managed code at the moment (there's some native shell APIs that will do it but they're not particularly straight forward).
-
Oct 8th, 2012, 03:22 AM
#3
Thread Starter
Fanatic Member
Re: Get exe from shortcut no api or vbscript
No that all I know I only really wanted something to read the exe from the shortcut, To create shortcuts I use the VBScript object. Though I am sure you can make a raw shortcut creator in VB with out API or VBScript, just need to get your hands on the file format.
-
Oct 8th, 2012, 07:52 AM
#4
Re: Get exe from shortcut no api or vbscript
Yeah exactly, but I've never come across anywhere that actually explains the LNK file format
-
Oct 8th, 2012, 07:54 AM
#5
Re: Get exe from shortcut no api or vbscript
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
|