Create a File Shortcut

1) Open a new exe standard proyect

2) Add one CommandButton, and two Textboxes, called cmdMakeLNKFile, txtTarget and txtLnkName respectively

3) Add the reference to the Windows Script Host Object Model (file: wshom.ocx, located in your system directory)

4) Copy this code to the Declarations sections:
       Dim Shell As WshShell
       Dim Shortcut As WshShortcut

5) Add this code to your form

Private Sub cmdMakeLNKFile_Click()

  'initialize the object WshShell
  Set objShell = New WshShell

  'initialize the object WshShortcut
  'the complete name of the .lnk file, include full path plus the .LNK file extension
  Set objShortcut = objShell.CreateShortcut (txtLnkName.Text)

  'the file to be called by the .lnk file, ej. "c:\windows\calc.exe"
  objShortcut.TargetPath = txtTarget.Text
 
  '(optional) := any command line supported by the file indicated in txtTarget.Text
  'objShortcut.Arguments = xxxx

  '(optional) : = a valid icon file : = To use the same icon of the target file, do not use the next line.
  'objShortcut.IconLocation = xxxx
 
  'Save the .lnk
  objShortcut.Save

End Sub

You might also like...

Comments

Carlos Icaza

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup