如何寫程式建立桌面捷徑 ( Shortcut )

如何寫程式建立桌面捷徑 ( Shortcut )

如何 透過寫程式 建立 桌面捷徑 ( Shortcut )

Private Sub Command1_Click _

(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click

CreateShortCut("C:\MyApp" , "abc.exe" , " 捷徑描述 " )

End Sub

Sub CreateShortCut(ByRef strFolder As String, ByRef strEXE As String, ByRef strDesc As String)

Dim objWS As Object

objWS = CreateObject("WScript.Shell")

With objWS.CreateShortCut(.SpecialFolders("Desktop") & "\" & Replace(strEXE, ".EXE", ".LNK", 1, , 1))

.TargetPath = objWS.ExpandEnvironmentStrings(strFolder & "\" & strEXE)

.WorkingDirectory = strFolder

.Description = strDesc

.WindowStyle = 4

.IconLocation = objWS.ExpandEnvironmentStrings(strFolder & "\" & strEXE & ",0")

.Save()

End With

End Sub