Search Tools Links Login

create a Shelllink (also known as Shortcut) with a few lines of code


Visual Basic 6, or VB Classic

It creates a shortcut and lets you define all important parameters. I have seen some examples before, but they where all too complicated for this little job. So I collected informationen and wrote this.

Original Author: Max Christian Pohle

Inputs

for example
CreateShortcut App.Path & "Explorer.lnk", "C:winntexplorer.exe", "", "CTRL+SHIFT+D", "Microsoft Windows Explorer", Maximized, 0
creates a link in your applications path which calls the explorer.exe from "c:winnt", defines CTRL+Shift+D as keycombination for it, starts the Explorer-window maximized and uses the standardicon of explorer.exe, which is 0.

Returns

Returns? The shortcut :-)

API Declarations

no APIs used, but Windows-Scriptinghost
Thats why it should run as "VB Script" as well ( with little modifications maybe :-) )

Code

Option Explicit
Enum Windowstyle
  Minimized = 7
  Maximized = 3
  Normal = 1
End Enum
Public Function CreateShortcut(Linkpath As String, TargetPath As String, Optional WorkPath As String, Optional HotKey As String = "", Optional Description As String = "", Optional Winstyle As Windowstyle, Optional Iconnumber As Integer)
  Dim SC As Object
  Set SC = CreateObject("Wscript.Shell").CreateShortcut(Linkpath)
  
  With SC
    .TargetPath = TargetPath
    'where your shortcuts jumps to
    
    .HotKey = HotKey
    'can be "CTRL+SHIFT+E" (as Str!) for Example
    
    .Description = Description
    'this should be clear to you
    
    .Windowstyle = Winstyle
    'Winstyle differs from the typical styles (2 does not mean maximized)
    
    .IconLocation = TargetPath & ", " & Iconnumber
    'This will take the Icon for the link from the file its associated with (targetpath)
    'some files include more than one icon. This is what is meant by Iconnumber.
    
    .WorkingDirectory = WorkPath
    'The normal Workingdirectory for the file the link calls.
    
    .Save
    'saves the link [important! :-)]
  End With
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 263 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.