Hi again. I’m using Xojo 2019r1 on windows.
I’m wondering if anyone knows of any tutorials or info about how use Xojo to create a windows shortcut.
Any info at all would be most appreciated, as I haven’t been able to find anything.
You could create a windows script file and execute that using Shell. Have a look at https://stackoverflow.com/questions/26006735/creating-a-lnk-in-vbs
HTH
Wayne
Or use OLE to access the scripting host directly:
Public Function CreateShortcut(Target As FolderItem, Name As String) As FolderItem
#If TargetWin32 Then
Dim shortcut As FolderItem = SpecialFolder.Temporary.Child(Name + ".lnk")
Dim WSHScript As New OLEObject("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}")
Dim WSHShortcut As OLEObject = WSHScript.CreateShortcut(shortcut.NativePath)
If WSHShortcut <> Nil Then
WSHShortcut.Description = Name
WSHShortcut.TargetPath = Target.NativePath
WSHShortcut.WorkingDirectory = Target.NativePath
WSHShortcut.Save()
Return shortcut
End If
#endif
End Function
That’s how I’ve done it, too.
Here is an example project for Windows, macOS and Linux: GitHub: jo-tools/createshortcut
WOW! Thanks for all the info, guys. I’ll give it all a go and let you know how I make out.
I’ve got this working, but how do I define the icon or png to use? I get a generic icon at present.
EDIT: I’m trying the following, but starting my project throws an OLEException on “IconLocation”:
WSHShortcut.IconLocation = SpecialFolder.CurrentWorkingDirectory.Child("QM_48.png")
EDIT 2: Solved it. Needed “.NativePath”, and can’t use a png, must be an ico file.
Thanks for the assist!
Please post an example of the final, corrected, code.
Thank you.