如何在没有安装程序的情况下在vb.net中创建桌面快捷方式

时间:2011-04-06 16:29:58

标签: vb.net winforms windows-installer desktop-shortcut

我想通过程序为exe文件创建桌面快捷方式。 我不想使用安装程序来执行此操作。 程序中的一段代码可以这样做吗?怎么样?

2 个答案:

答案 0 :(得分:10)

几年前,{p> Chasler回答了这个问题here on SO

添加对Windows脚本宿主对象模型的引用

Imports IWshRuntimeLibrary

Private Sub CreateShortCut(ByVal FileName As String, ByVal Title As String)
    Try
        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

Source

答案 1 :(得分:3)

此代码效果很好

ball.physicsBody?.applyImpulse(CGVector(dx: 20, dy: 20))

Credits