Create Desktop Shortcut (1 Viewer)

Cotty42

Registered User.
Local time
Today, 19:37
Joined
Feb 27, 2014
Messages
102
I found this code really useful when setting up BE/FE Database and copying FE to users personal drive. The function will create a shortcut to the FE software on the users desktop so the user doesn't have to search for it.

The function takes 2 paramaters, strFileName = The name of the link created (what will appear on the desktop) and strTargetFileName = the path and filename of the FE file that the shortcut points to.

Code:
Public Function CreateShortCut(strFileName, strTargetFileName)
    Dim oWSH As Object
    Dim oShortcut As Object
    Dim sPathDeskTop As String
    Set oWSH = CreateObject("WScript.Shell")
    sPathDeskTop = oWSH.SpecialFolders("Desktop")
'   *** Removes file extension and replaces with '.lnk'
    FileDot = InStr(strFileName, ".")
    strShortCutName = Left$(strFileName, FileDot) & "lnk"
    
    Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & strShortCutName)
    With oShortcut
        .TargetPath = strTargetFileName
        .Save
    End With
    Set oWSH = Nothing
End Function

Hope you find this useful

Dave
 

Users who are viewing this thread

Top Bottom