Does anyone know a way to create a shortcut or a link through visual basic code. I have found some samples that work only with Windows '95, but it is really important that the code works with win95,98,NT4,2000.
1. Start a New Standard.Exe Project.
2. Add a ListBox (List1) to Form1.
3. Copy/Paste the following into the Form1 code window.
4. CHANGE the i_strShortcut variable to a valid Shortcut.
5. Press F5 to run. Click on VB Menu -> View -> Immediate Window and you will see all pertinent Shortcut information for the Link specified.
<----- Code begin ----->
Option Explicit
Private Sub Form_Load()
Dim strLinkSource As String
strLinkSource = "c:\win95b\desktop\windows explorer.lnk" ' <-- CHANGE
Dim strLinkTarget As String
strLinkTarget = "c:\win95b\desktop\TEST.lnk" ' <-- CHANGE
Private Sub x_Link_Copy(ByVal i_strSource As String, ByVal i_strTarget As String)
If Dir(i_strSource) = "" Then
MsgBox i_strSource & " NOT FOUND", vbCritical
Exit Sub
End If
If Dir(i_strTarget) <> "" Then
MsgBox i_strTarget & " ALREADY EXISTS", vbCritical
Exit Sub
End If
Dim wshShell As Object
Set wshShell = CreateObject("WScript.Shell"
Dim wshSource As Object
Set wshSource = wshShell.CreateShortcut(i_strSource)
With wshSource
Call x_Link_Write _
(i_strTarget, _
.Arguments, _
.Description, _
.Hotkey, _
.IconLocation, _
.TargetPath, _
.WindowStyle, _
.WorkingDirectory)
End With
Set wshShell = Nothing
End Sub
Private Sub x_Link_Read(ByVal i_strShortcut As String)
If Dir(i_strShortcut) = "" Then
MsgBox i_strShortcut & " NOT FOUND", vbCritical
Exit Sub
End If
Dim wshShell As Object
Set wshShell = CreateObject("WScript.Shell"
Dim wshLink As Object
Set wshLink = wshShell.CreateShortcut(i_strShortcut)
Private Sub x_Link_Write _
(ByVal i_strShortcut As String, _
ByVal i_strArguments As String, _
ByVal i_strDescription As String, _
ByVal i_strHotkey As String, _
ByVal i_strIconLocation As String, _
ByVal i_strTargetPath As String, _
ByVal i_strWindowStyle As String, _
ByVal i_strWorkingDirectory As String)
Dim wshShell As Object
Set wshShell = CreateObject("WScript.Shell"
Dim wshLink As Object
Set wshLink = wshShell.CreateShortcut(i_strShortcut)
With wshLink
.Arguments = i_strArguments
.Description = i_strDescription
.Hotkey = i_strHotkey
.IconLocation = i_strIconLocation
.TargetPath = i_strTargetPath
.WindowStyle = i_strWindowStyle
.WorkingDirectory = i_strWorkingDirectory
End With
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.