Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 30,754 times

Related Categories

Create a File Shortcut

cicaza

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

Comments

  • Re: [2329] Create a File Shortcut

    Posted by Vitus13 on 09 Sep 2007

    Hello,
         I have used your code and it has worked well for me till now. I have added the .Ocx and the Dim statements and all has gone well. However now that I run the progr...

  • Re: [2329] Create a File Shortcut

    Posted by Vitus13 on 09 Sep 2007

    Hello,
         I have used your code and had success adding in the Ocx and the Dim statements, However... When I run the application I recieve a ComException. the report goes s...

  • Confused??? please help i'm stuck

    Posted by bocay on 07 Dec 2003

    :confused:
    I'm using this code but sometimes i get the message "set [u]objshell[/u] doesn't declare" i've assign the "WSHOM.OCX" things and the "dim " things..
    BUT
    sometimes it works, but sometim...

  • Read the value

    Posted by Opo on 17 Oct 2003

    Hello !

    When the shortcut is created, how can I read with VB or another language the value of arguments and targetpath ?

    Thanks !

  • Great code!

    Posted by liviucristian on 31 May 2002

    This code comes in handy when creating a setup program the creates shortcuts to programs. I like it because it works with few lines of code. Thank you very much! I've been looking for this for a very...