Create an Internet Shortcut (.URL) File Using Delphi

hands typing on a laptop

Jamie Grill / Getty Images

Unlike regular .LNK shortcuts (that point to a document or an application), Internet Shortcuts point to a URL (web document). Here's how to create a .URL file, or Internet Shortcut, using Delphi.

The Internet Shortcut object is used to create shortcuts to Internet sites or web documents. Internet shortcuts are diverse from regular shortcuts (which contain data in a binary file) that point to a document or an application. Such text files with a .URL extension have their content in INI file format.

The easiest way to look inside a .URL file is to open it inside Notepad. The content (in its simplest form) of an Internet Shortcut could look like this:

As you can see, .URL files have an INI file format. The URL represents the address location of the page to load. It must specify a fully qualifying URL with the format protocol://server/page..

Simple Delphi Function to Create an .URL File

You can easily programmatically create an Internet shortcut if you have the URL of the page to which you want to link. When double-clicked, the default browser is launched and displays the site (or a web document) associated with the shortcut.

Here's a simple Delphi function to create a .URL file. The CreateInterentShortcut procedure creates a URL shortcut file with the provided file name (FileName parameter) for the given URL (LocationURL), overwriting any existing Internet Shortcut with the same name.

Here's a sample usage:

A few notes:

  • You could save a web page as MHT (web archive) and then create a .URL shortcut to be able to access an offline version of a web document.
  • You must provide a full file name, along with the .URL extension, for the FileName parameter.
  • If you already have an Internet Shortcut you are "interested in", you can easily extract the URL from an Internet Shortcut (.url) file.

Specifying the .URL Icon

One of the neater features of the .URL file format is that you can change the shortcut's associated icon. By default the .URL will carry the icon of the default browser. If you want to change the icon, you only have to add two additional fields to the .URL file, as in:

The IconIndex and IconFile fields let you specify the icon for the .URL shortcut. The IconFile could point to your application's exe file (IconIndex is the index of the icon as a resource inside the exe).

Internet Shortcut to Open a Regular Document or an Application

Being called an Internet Shortcut, a .URL file format does not permit you to use it for something else—such as a standard application shortcut.

Note that the URL field must be specified in the protocol://server/page format. For example, you could create an Internet Shortcut icon on the Desktop that points to your program's exe file. You only need to specify the "file:///" for the protocol. When you double click on such a .URL file, your application will be executed. Here's an example of such an "Internet Shortcut":

Here's a procedure that places an Internet Shortcut on the Desktop, the shortcut points to the *current* application. You can use this code to create a shortcut to your program:

Note: simply call "CreateSelfShortcut" to create a shortcut to your program on the Desktop.

When to Use .URL

Those handy .URL files will be useful for virtually every project. When you create a setup for your applications, include a .URL shortcut inside the Start menu—let users have the most convenient way to visit your website for updates, examples, or help files.

mla apa chicago
Your Citation
Gajic, Zarko. "Create an Internet Shortcut (.URL) File Using Delphi." ThoughtCo, Feb. 16, 2021, Gajic, Zarko. (2021, February 16). Create an Internet Shortcut (.URL) File Using Delphi. Retrieved from Gajic, Zarko. "Create an Internet Shortcut (.URL) File Using Delphi." ThoughtCo. (accessed June 9, 2023).