Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Create desktop shortcut


'reference to Windows Script Host Object Model is required

'this version goes to a folder of your choice
Dim wShell As New IWshShell_Class
Dim wShortcut As IWshShortcut_Class
Set wShortcut = wShell.CreateShortcut( "d:\test.lnk" )
wShortcut.TargetPath = "d:\test.txt"
wShortcut.Save

'and this version goes to the desktop
Dim wShell As New IWshShell_Class
Dim wShortcut As IWshShortcut_Class

Dim sDesktop As String               ' path of desktop
Dim sTargetPath As String          ' path to file for which a link is to be created

sDesktop = wShell.SpecialFolders.Item( "Desktop" )
sTargetPath = wShell.ExpandEnvironmentStrings( "%windir%" )

Set wShortcut = wShell.CreateShortcut(sDesktop & "filename.lnk" )

wShortcut.TargetPath = sTargetPath & "\filename.exe"
wShortcut.Arguments = ""
wShortCut.WorkingDirectory = sDesktop
wShortCut.Save