How to create a shortcut - VB#25 ~ VBTheory™ Tutorials

Friday, November 7, 2014

How to create a shortcut - VB#25

Download IWshRuntimeLibrary:
Link

Code:

Imports IWshRuntimeLibrary

Public Class Form1

    Private Sub BtnPath_Click(sender As Object, e As EventArgs) Handles BtnPath.Click
        Dim s As New SaveFileDialog()
        s.Filter = "Shortcut (*.lnk)|*.lnk"

        If (s.ShowDialog() <> DialogResult.OK) Then Return

        If (s.FileName.EndsWith(".lnk")) Then TxtPath.Text = s.FileName
    End Sub

    Private Sub BtnFile_Click(sender As Object, e As EventArgs) Handles BtnFile.Click
        Dim o As New OpenFileDialog()
        o.Filter = "Any file (*.*)|*.*"

        If (o.ShowDialog() <> DialogResult.OK) Then Return

        TxtTarget.Text = o.FileName
    End Sub

    Private Sub BtnFolder_Click(sender As Object, e As EventArgs) Handles BtnFolder.Click
        Dim f As New FolderBrowserDialog()

        If (f.ShowDialog() <> DialogResult.OK) Then Return

        TxtTarget.Text = f.SelectedPath
    End Sub

    Private Sub BtnIcon_Click_1(sender As Object, e As EventArgs) Handles BtnIcon.Click
        Dim o As New OpenFileDialog()
        o.Filter = "Icon file (*.ico)|*.ico"

        If (o.ShowDialog() <> DialogResult.OK) Then Return

        TxtIcon.Text = o.FileName
    End Sub

    Private Sub BtnCreate_Click(sender As Object, e As EventArgs) Handles BtnCreate.Click
        Dim wsh As New WshShellClass()
        Dim shortcut As IWshShortcut = wsh.CreateShortcut(TxtPath.Text)

        shortcut.TargetPath = TxtTarget.Text
        shortcut.Description = TxtDescription.Text
        shortcut.IconLocation = TxtIcon.Text

        shortcut.Save()
    End Sub
End Class



Post a Comment (0)

Share