Hallo Zusammen,
es gibt hier im Forum einige, meist ältere Beiträge, zu dem Thema wie erstellt man Verknüpfungen / Links.
Was mich jedoch etwas stört ist wie diese Codes aufgebaut sind. Das Beispiel nutzt als Ansatz Microsoft Shell Controls And Automation (Imports Shell32).
Beispielcode:
Source: vbarchiv.net/tipps/details.php?id=1601
Gibt's denn keine Möglichkeit mit den Boardmitteln von .NET einen Link zu erstellen?
Wie habt Ihr in euren Anwendungen etwas derartiges realisiert?
Gruß, FireEmerald
es gibt hier im Forum einige, meist ältere Beiträge, zu dem Thema wie erstellt man Verknüpfungen / Links.
Was mich jedoch etwas stört ist wie diese Codes aufgebaut sind. Das Beispiel nutzt als Ansatz Microsoft Shell Controls And Automation (Imports Shell32).
VB.NET-Quellcode
- Public Function CreateShortcut(ByVal _LinkFullPath As String, _
- ByVal _LinkFullTargetPath As String, _
- Optional ByVal _Description As String = "", _
- Optional ByVal _Arguments As String = "", _
- Optional ByVal _WorkingDir As String = "") As Boolean
- Try
- Dim _Shell As New Shell
- Dim _Folder As Folder
- Dim _LinkObject As ShellLinkObject
- ' Ordner und Dateinamen extrahieren
- Dim _LinkFolderPath As String = _LinkFullPath.Substring(0, _LinkFullPath.LastIndexOf("\"))
- Dim _LinkFilename As String = _LinkFullPath.Substring(_LinkFullPath.LastIndexOf("\") + 1)
- ' Wichtig! Link-Datei erstellen (0 Bytes)
- Dim F As Short = FreeFile()
- FileOpen(F, _LinkFullPath, OpenMode.Output)
- FileClose(F)
- _Folder = _Shell.NameSpace(_LinkFolderPath)
- oLink = oFolder.Items.Item(sFile).GetLink
- ' Eigenschaften der Verknüpfung
- With _LinkObject
- If _Arguments.Length > 0 Then .Arguments = _Arguments
- If _Description.Length > 0 Then .Description = _Description
- If _WorkingDir.Length > 0 Then .WorkingDirectory = _WorkingDir
- .Path = _LinkFullTargetPath
- ' Verknüpfung speichern
- .Save()
- End With
- ' Objekte zerstören
- _LinkObject = Nothing
- _Folder = Nothing
- _Shell = Nothing
- Return True
- Catch ex As Exception
- ' Fehler! ggf. Link-Datei löschen, falls bereit erstellt
- If System.IO.File.Exists(_LinkFullPath) Then Kill(_LinkFullPath)
- Return False
- End Try
- End Function
Gibt's denn keine Möglichkeit mit den Boardmitteln von .NET einen Link zu erstellen?
Wie habt Ihr in euren Anwendungen etwas derartiges realisiert?
Gruß, FireEmerald