Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding what .LNK Shorcuts point to 2

Status
Not open for further replies.

everytime

Programmer
Joined
Feb 21, 2001
Messages
31
Location
GB
Can someone give me some advice on creating shortcut files (in the windows start menu for example) dynamically in code. Also is there a way to check what an existing shortcut points to in code.
Thanks in advance,

everytime
 
I am not sure about getting the full path for a specified shortcut, but I have written a routine to create desktop shortcuts on new PCs. I am sure you can modify this to suit you needs.
Code:
Private Declare Function fCreateShellLink Lib "Vb5stkit.dll" (ByVal _
                lpstrFolderName As String, _
                ByVal lpstrLinkName As String, _
                ByVal lpstrLinkPath As String, _
                ByVal lpstrLinkArgs As String) As Long


Sub CreateShortcut(sDisplayName As String, sFullPath As String)
    Dim lReturn As Long
    Dim sDeskName As String
    Dim sLinkArgs As String
    On Error GoTo ErrHndlr
    'Add to Desktop
    sDeskName = "..\..\Desktop"
    sLinkArgs = ""
    lReturn = fCreateShellLink(sDeskName, sDisplayName, sFullPath, sLinkArgs)
    If lReturn <> 1 Then
        MsgBox &quot;There was an error creating the shortcut:&quot; & vbCrLf & sDisplayName & vbCrLf & sFullPath
    End If
    Exit Sub
ErrHndlr:
    sDeskName = &quot;System Error in CreateShortcut()!&quot;
    sDeskName = sDeskName & &quot;Error No: &quot; & Err.Number & vbCrLf & &quot;Error Desc: &quot; & Err.Description
    sDeskName = sDeskName & vbCrLf & sDisplayName & vbCrLf & sFullPath
    Err.Clear
    MsgBox sDeskName
End Sub

'To Create a Shortcut:
Call CreateShortcut(&quot;Ratings Program&quot;, &quot;\\H4MWN\Applications\Thermal\Ratings.exe&quot;)

Hope this helps!
 
Top work dsi, I will check that out.

If anyone knows how to get the full path of an existing shortcut, let me know!
 
You may want to post that question in the General VB Forum. It may get a little more exposure.
 
Okay... this is cheating a bit but it works. Place a file list box on a form and set the path appropriately. Then click an LNK file.
[tt]
Private Sub File1_Click()
MyPath$ = &quot;d:\windows\desktop\&quot;
ff = FreeFile
Open MyPath$ & File1.FileName For Binary As #ff
G$ = String$(LOF(ff), 0)
Get #ff, 1, G$
Close #ff
StartPath = InStr(G$, &quot;:\&quot;)
StartPath = InStr(StartPath + 3, G$, &quot;:\&quot;) - 1
EndPath = InStr(StartPath, G$, String$(2, 0))
MsgBox &quot;Here's your application path: &quot; _
& Mid$(G$, StartPath, EndPath - StartPath)
End Sub
[/tt]

As I noted, this is cheating and won't work 100% of the time. It works under the assumption that the link is local (not a networked association).

The LNK file format is complex and the documentation is sparce. If you feel up to the task of creating an &quot;error free&quot; version of the preceding code you can find a fair description of the shortcut format at
Hey, it will take a little work but Tek-Tips members will adore you like a god if you spend the time to unravel this little Microsoft Mystery.
VCA.gif

Alt255@Vorpalcom.Intranets.com
Klatu barada nikto, y'all.
 
Cheers Alt. I will see what I can do!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top