次のコードは、スタートメニューに実行中のアプリケーションへのショートカットを作成します(これを行うには、必要な権限が必要です)。
まず、[参照の追加]->[COM]タブ->[WindowsScriptHostオブジェクトモデル]
Imports IWshRuntimeLibrary
Public Function CreateShortcut(ByVal fileName As String, ByVal description As String) As Boolean
Try
Dim shell As New WshShell
'the following is the root of the Start Menu so if you want it in a folder you need to create it
Dim ShortcutDir As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu)
Dim shortCut As IWshRuntimeLibrary.IWshShortcut
' short cut files have a .lnk extension
shortCut = CType(shell.CreateShortcut(ShortcutDir & "\" & fileName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
' set the shortcut properties
With shortCut
.TargetPath = System.Reflection.Assembly.GetExecutingAssembly.Location()
.WindowStyle = 1
.Description = description
.WorkingDirectory = ShortcutDir
' the next line gets the first Icon from the executing program
.IconLocation = System.Reflection.Assembly.GetExecutingAssembly.Location() & ", 0"
'.Arguments = ""
.Save()
End With
Return True
Catch ex As System.Exception
' add your error handling here
Return False
End Try
End Function