by H W Samuel (4 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 6th February 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Create shortcuts to files on any location under program control, such as desktop, startup, etc. using the Shell object
API Declarations
Public Enum SHORTCUT_LOCATIONS
DesktopAll = 0
StartMenuAll = 1
ProgramsAll = 2
StartupAll = 3
DesktopNow = 4
ApplicationDataNow = 5
PrintHoodNow = 6
TemplatesNow = 7
WinFonts = 8
NetHoodNow = 9
DesktopNowAlt = 10
StartMenuNow = 11
SendToNow = 12
RecentNow = 13
StartUpNowAlt = 14
FavouritesNow = 15
MyDocsNow = 16
ProgramsNow = 17
End Enum
'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
No comments have been posted about Create shortcuts to files on any location under program control, such as desktop, startup, etc. usi. Why not be the first to post a comment about Create shortcuts to files on any location under program control, such as desktop, startup, etc. usi.