Page 1 of 1
Create shortcut for accessing URL
Posted: Sat Feb 08, 2025 6:25 pm
by don lowenstein
I'm trying to create a Windows shortcut in Harbour for accessing a URL with my browser.
Has anyone had success doing this?
Thanks in advance for any assistance.
Re: Create shortcut for accessing URL
Posted: Sat Feb 08, 2025 8:35 pm
by Antonio Linares
Dear Don,
Not sure if you mean this:
Code: Select all | Expand
PROCEDURE CreateURLShortcut(cFileName, cURL)
LOCAL hFile
// Ensure the filename ends with .url
IF AT(".url", LOWER(cFileName)) == 0
cFileName += ".url"
ENDIF
// Create and write to the file
hFile := FCreate(cFileName)
IF hFile != -1
FWrite(hFile, "[InternetShortcut]" + Chr(13) + Chr(10))
FWrite(hFile, "URL=" + cURL + Chr(13) + Chr(10))
FClose(hFile)
ELSE
? "Error creating file:", cFileName
ENDIF
RETURN
// Usage:
CreateURLShortcut("MyWebShortcut.url", "https://www.example.com")
or maybe this:
Code: Select all | Expand
PROCEDURE CreateLNKShortcut(cLnkPath, cURL)
LOCAL oShell, oShortcut
// Initialize COM (if not already done)
IF !Empty(GetActiveObject("WScript.Shell"))
oShell := CreateObject("WScript.Shell")
ELSE
? "COM initialization failed."
RETURN
ENDIF
// Create the shortcut
oShortcut := oShell:CreateShortcut(cLnkPath)
oShortcut:TargetPath := "rundll32.exe"
oShortcut:Arguments := "url.dll,FileProtocolHandler " + cURL
oShortcut:Save()
RETURN
// Usage:
CreateLNKShortcut("MyWebShortcut.lnk", "https://www.example.com")
Re: Create shortcut for accessing URL
Posted: Sat Feb 08, 2025 9:27 pm
by leandro
Re: Create shortcut for accessing URL
Posted: Sat Feb 08, 2025 11:45 pm
by don lowenstein
Thanks for the suggestions.
I'll test them on Monday.
Antonio, it's good to hear from you. I hope all is well with you and yours.
Don
Re: Create shortcut for accessing URL
Posted: Sat Feb 08, 2025 11:50 pm
by don lowenstein
I noticed that all three of us on this thread joined the FiveTech forum in October 2005.
That's a testament to how good the Fivewin libraries and community are.
I feel privileged to be part of it.
Sincerely, Don
Re: Create shortcut for accessing URL
Posted: Mon Feb 10, 2025 2:18 pm
by don lowenstein
PROCEDURE CreateURLShortcut(cFileName, cURL)
This worked perfectly - Thanks.