Is there a way to make a shortcut to an exe file with vb6?
Hi there folks! I am going to share some of the programs I've been working on with other teachers soon, and I was wondering if there is a line of code that will make a shortcut for the .exe file to the user's desktop.
All of the programs I have been making are just .exe files and some mp3 files. Because of strict computer policies, making an install is out, besides when the teacher doesn't want it anymore, they just can just delete the folder. The programs are simple and I don't think have dependencies on system files.
The teachers laptop will most likely have a 64 bit windows 7, with perhaps a small percentage using windows 10 if that info is important.
Thanks a lot!
Re: Is there a way to make a shortcut to an exe file with vb6?
In a project with oleexp or another TLB with IShellLinkW and IPersistFile,
Code:
Public Sub SaveNewLink(sLink As String, _
sPath As String, _
Optional sIconFile As String = vbNullString, _
Optional ByVal lIcon As Long = 0, _
Optional ByVal iHK As Integer = 0, _
Optional sArgs As String = vbNullString, _
Optional sDesc As String = vbNullString, _
Optional ByVal pidl As Long = 0, _
Optional sWorkDir As String = vbNullString, _
Optional sRelPath As String = vbNullString, _
Optional swc As ShowWindowTypes = SW_NORMAL)
Dim csl As ShellLinkW
Dim ipf As IPersistFile
Set csl = New ShellLinkW
Set ipf = csl
With csl
.SetPath (sPath)
.SetArguments sArgs
.SetDescription sDesc
.SetIconLocation sIconFile, lIcon
.SetHotkey iHK
.SetShowCmd swc
.SetRelativePath sRelPath, 0
.SetWorkingDirectory sWorkDir
If pidl Then .SetIDList pidl
.Resolve 0, SLR_UPDATE
End With
ipf.Save sLink, 0
Set ipf = Nothing
Set csl = Nothing
End Sub
sLink is the name of the shortcut, and must include the super well-hidden .lnk extension, e.g. C:\Folder\My Program.exe.lnk
1 Attachment(s)
Re: Is there a way to make a shortcut to an exe file with vb6?
There are a couple of ways to do this. Here is another one, and I have taken into account a few weirdnesses about shortcut property settings, such as the icon location.
Code:
Option Explicit
Private Sub CreateShortcut()
Const SW_SHOWNORMAL = 1
Dim AppPath As String
Dim FullExeName As String
Dim Desktop As String
Dim FullShortcutName As String
Dim IconPath As String
AppPath = App.Path
If Right$(AppPath, 1) <> "\" Then AppPath = AppPath & "\"
FullExeName = AppPath & App.EXEName & ".exe"
With CreateObject("WScript.Shell")
Desktop = .SpecialFolders("Desktop")
FullShortcutName = Desktop & "\" & App.EXEName & ".lnk"
On Error Resume Next
GetAttr FullShortcutName
If Err Then 'No shortcut yet!
On Error GoTo 0
With .CreateShortcut(FullShortcutName)
.Description = App.FileDescription
If UCase$(Desktop) = UCase$(Left$(AppPath, Len(Desktop))) Then
IconPath = "%USERPROFILE%\Desktop" & Mid$(FullExeName, Len(Desktop) + 1)
Else
IconPath = FullExeName
End If
.IconLocation = IconPath & ",0" '0 is the icon index
.TargetPath = FullExeName
.WindowStyle = SW_SHOWNORMAL
.WorkingDirectory = AppPath
.Save
End With
End If
End With
End Sub
Private Sub Main()
CreateShortcut
ShortyUI.Show
End Sub
Re: Is there a way to make a shortcut to an exe file with vb6?
i'd use cmd.exe mklink.
it does require administrator privileges though, so depending on how strict those policies are, it may just not help you.
Code:
Public Sub CreateLink(linkPath As String, linkName As String)
Shell ("cmd /c mklink %userprofile%\Desktop\" & _
Chr(34) & linkName & Chr(34) & _
" " & _
Chr(34) & linkPath & Chr(34))
End Sub
usage:
Code:
Call CreateLink("C:\myexefile.exe", "my link name.lnk")
Re: Is there a way to make a shortcut to an exe file with vb6?
There is also code in the source for the PD wizard that does this. Has been a long time since I looked at it but I do remember adding code to it to give the user the option of placing a shortcut on the desktop as part of the install.