Pages

Tuesday, 18 October 2011

Create Desktop Shortcut


' =============================================================
' function: CreateDesktopShortcut
' desc :    Creates a shortcut on the desktop
' params :  strTargetPath is the full path to the file you 
'           are creating the shortcut to, i.e. c:\doc\me.txt
'           strLinkName is the name of the shortcut, as it 
'           appears on the desktop
'           strDesc is the description to set within the shortcut
' returns : void
' =============================================================
Sub CreateDesktopShortcut(strTargetPathstrLinkNamestrDesc)

Dim objShellobjShortCut
Dim strDesktopFolder

' ensure that the link name is valid
if Right(Lcase(strLinkName,4)) <> ".lnk" Then strLinkName = strLinkName & ".lnk"

' create a shell object 
Set objShell = CreateObject("WScript.Shell")

' get the desktop folder
strDesktopFolder = objShell.SpecialFolders("AllUsersDesktop")

' create required shortcut object on the desktop
Set objShortCut = objShell.CreateShortcut(strDesktopFolder & "\" & strLinkName)

' set the path within the shortcut
objShortCut.TargetPath = strTargetPath

' set the description
objShortCut.Description = strDesc

' save the shortcut
objShortCut.Save

End Sub ' CreateDesktopShortcut

0 comments:

Post a Comment