By looking at it that seems like it's what you're looking for. Enjoy.
If you have any trouble understanding the code, let me know.
[php] Public Function CreateShortcut(ByVal sLinkFile As String, _
ByVal sTargetFile As String, _
Optional ByVal sArguments As String = "", _
Optional ByVal sDescription As String = "", _
Optional ByVal sWorkingDir As String = "") As Boolean
Try
Dim oShell As New Shell32.Shell
Dim oFolder As Shell32.Folder
Dim oLink As Shell32.ShellLinkObject
' extract folder / filename
Dim sPath As String = sLinkFile.Substring(0, sLinkFile.LastIndexOf("\"))
Dim sFile As String = sLinkFile.Substring(sLinkFile.LastIndexOf("\") + 1)
' Wichtig! Link-Datei erstellen (0 Bytes)
Dim F As Short = FreeFile()
FileOpen(F, sLinkFile, OpenMode.Output)
FileClose(F)
' shortcut properties
With oLink
If sArguments.Length > 0 Then .Arguments = sArguments
If sDescription.Length > 0 Then .Description = sDescription
If sWorkingDir.Length > 0 Then .WorkingDirectory = sWorkingDir
.Path = sTargetFile
Catch ex As Exception
' Error! delete shortcut if it already exists
If System.IO.File.Exists(sLinkFile) Then Kill(sLinkFile)
Return False
End Try
End Function
[/php]
[php] Dim desk As String = Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
Try
CreateShortcut(IO.Path.Combine(desk, "Recorder.lnk"), Application.ExecutablePath)
Catch ex As Exception
End Try[/php]
Originally Posted by Blubb1337
[php] Public Function CreateShortcut(ByVal sLinkFile As String, _
ByVal sTargetFile As String, _
Optional ByVal sArguments As String = "", _
Optional ByVal sDescription As String = "", _
Optional ByVal sWorkingDir As String = "") As Boolean
Try
Dim oShell As New Shell32.Shell
Dim oFolder As Shell32.Folder
Dim oLink As Shell32.ShellLinkObject
' Ordner und Dateinamen extrahieren
Dim sPath As String = sLinkFile.Substring(0, sLinkFile.LastIndexOf("\"))
Dim sFile As String = sLinkFile.Substring(sLinkFile.LastIndexOf("\") + 1)
' Wichtig! Link-Datei erstellen (0 Bytes)
Dim F As Short = FreeFile()
FileOpen(F, sLinkFile, OpenMode.Output)
FileClose(F)
' Eigenschaften der Verknüpfung
With oLink
If sArguments.Length > 0 Then .Arguments = sArguments
If sDescription.Length > 0 Then .Description = sDescription
If sWorkingDir.Length > 0 Then .WorkingDirectory = sWorkingDir
.Path = sTargetFile
Catch ex As Exception
' Fehler! ggf. Link-Datei löschen, falls bereit erstellt
If System.IO.File.Exists(sLinkFile) Then Kill(sLinkFile)
Return False
End Try
End Function
[/php]
[php] Dim desk As String = Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
Try
CreateShortcut(IO.Path.Combine(desk, "Recorder.lnk"), Application.ExecutablePath)
Catch ex As Exception
End Try[/php]
German notation is fail.
Well that can help me too...
if there are any codes that will make it easier, then please let me know it ^^
also please mark now this thread as "solved."
thanks to J-Deezy and to Blubb1337..
Didn't realise, translated noob
Just a note, (WSH) runtime library (IWshRuntimeLibrary) is the easiest way with the least code for creating a shortcut.
Right Click On Desktop > New > Shortcut > Type location of program
Originally Posted by Kallisti
Right Click On Desktop > New > Shortcut > Type location of program
I think he wanted it done programatically
VB.net Source.....Obviously we all know how to do it in the OS
Programatically it would be
Add Reference to Windows Host Script (Com)
then
[php]
Imports IWshRuntimeLibrary
[/php]
the code is
Code:
Dim WindowsHostShell As WshShellClass = New WshShellClass
Dim TShortC As IWshRuntimeLibrary.IWshShortcut
' The shortcut will be created on the desktop
Dim DesktopFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
TShortC = CType(WindowsHostShell.CreateShortcut("C:\FileLocation\OrSpecialLocaltion"), IWshRuntimeLibrary.IWshShortcut)
TShortC.TargetPath = Application.StartupPath & "\applicationname.exe"
TShortC.Save()