Author : H W Samuel
Date Submitted : 6/2/2005
Category : File Manipulation
Compatibility : VB 6
This code has been accessed 4513 times.
Task : Create shortcuts to files on any location under program control, such as desktop, startup, etc. using the Shell object
Declarations
Code
'Call this function with the proper arguments:
'stFileNameRef stores the name and path of the file to create the shortcut from
'stLocation is for where the shortcut will be created
'stLinkName is for the caption of the shortcut link created
Sub Create_Shortcuts(stFileNameRef As String, stLocation As SHORTCUT_LOCATIONS, stLinkName as String)
Dim objWshShell As Object
Dim objShellLink As Object
Dim strAutoStart
Set objWshShell = CreateObject("WScript.Shell")
strAutoStart = objWshShell.SpecialFolders(stLocation)
If Dir(stFileNameRef) = "" Then Exit Sub
Set objShellLink = objWshShell.CreateShortcut(strAutoStart & "\" & _ stLinkName & ".lnk")
With objShellLink
.TargetPath = stFileNameRef
.WindowStyle = 1
.Description = stLinkName
.Save
End With
Set objShellLink = Nothing
Set objWshShell = Nothing
End Sub