Library code snippets
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
Related articles
Related discussion
-
Problem with migration to C# (CoCreateInstanceEx)
by LRollison (1 replies)
-
VB6 Problem Creating Shortcuts
by rb1177 (0 replies)
-
how can i open a file
by kyawswarhtun (0 replies)
-
how to save any one form what i want?
by blackguy (5 replies)
-
Build an MP3 Player
by soybees (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
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 program I recieve a COMException.
The error number form the report says it's -2147467259. it is raised when I call Objshortcut.Save(),and the error reads "COMException was unhandled: Unable to save file: C:\...\...\Link.lnk
Any Help Would Be Appreciated
~Vitus
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 somethinglike this, ComException was unhandled: unable to save "C:\...\...\...\...\Link.lnk"
In the error report I retrived the Com error number which is -2147467259. the error occurs the first time I run this statement: objshortcut.Save()
Any Help Would Be Appreciated
~Vitus
I'm using this code but sometimes i get the message "set objshell doesn't declare" i've assign the "WSHOM.OCX" things and the "dim " things..
BUT
sometimes it works, but sometime it doesn't... Help me please
Hello !
When the shortcut is created, how can I read with VB or another language the value of arguments and targetpath ?
Thanks !
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 long time!
Happy programming!
This thread is for discussions of Create a File Shortcut.