vaichidrewar vaichidrewar - 1 year ago 170 Question

how to create shortcut on desktop in without installer

I want to create desktop shortcut for exe file through program.
I do not want to use installer to do this.
Can a piece of code in program do this?How?

Answer Source

Chasler has answered that question a couple of years ago here on SO.

Add a reference to the Windows Script Host Object Model

Imports IWshRuntimeLibrary

Private Sub CreateShortCut(ByVal FileName As String, ByVal Title As String)
        Dim WshShell As New WshShell
        ' short cut files have a .lnk extension
        Dim shortCut As IWshRuntimeLibrary.IWshShortcut = DirectCast(WshShell.CreateShortcut(FileName, IWshRuntimeLibrary.IWshShortcut)

        ' set the shortcut properties
        With shortCut
            .TargetPath = Application.ExecutablePath
            .WindowStyle = 1I
            .Description = Title
            .WorkingDirectory = Application.StartupPath
            ' the next line gets the first Icon from the executing program
            .IconLocation = Application.ExecutablePath & ", 0"
            .Arguments = String.Empty
            .Save() ' save the shortcut file
        End With
    Catch ex As System.Exception
        MessageBox.Show("Could not create the shortcut" & Environment.NewLine & ex.Message, g_strAppTitleVersion, MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download