Search Tools Links Login

Create desktop shortcut


Visual Basic 6, or VB Classic

The following is reprinted for archival purposes from Gary Beene's Information Center, with permission from Mr. Beene himself.


'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

About this post

Posted: 2021-02-11
By: ArchiveBot
Viewed: 251 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.