[Help]Making shortcuts[Solved]

Posts 1–10 of 10 · Page 1 of 1
[Help]Making shortcuts[Solved]
May I ask...
how to create your own shortcut link for your file??
since I want to make a program that makes a shortcut link to the desktop...

but I don't know what is the code for it...

Thanks for the person who can answer this,
[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)

oFolder = oShell.NameSpace(sPath)
oLink = oFolder.Items.Item(sFile).GetLink

' 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

' save shortcut
.Save()
End With

' remove object
oLink = Nothing
oFolder = Nothing
oShell = Nothing

Return True

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]
Quote Originally Posted by Blubb1337 View Post
[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)

oFolder = oShell.NameSpace(sPath)
oLink = oFolder.Items.Item(sFile).GetLink

' 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

' Verknüpfung speichern
.Save()
End With

' Objekte zerstören
oLink = Nothing
oFolder = Nothing
oShell = Nothing

Return True

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
Quote Originally Posted by Kallisti View Post
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()

Obviously Much Shorter


Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us