Unlike conventional ones. lnk shortcut (pointing to a document or application), network shortcut pointing to a URL (Web Document ). the following describes how to create. the Network Shortcut of the URL file, using the Delphi language.
The Network shortcut object is used to create shortcuts for Internet or Web documents. internet shortcuts are different from conventional shortcuts (including data in binary files). Conventional shortcuts point to a document or application. This text file with the. url extension contains the content in ini format.
Network shortcut (. url)
To create a network shortcut, drag the network to your desktop (or to another folder ). if you are using IE, drag the System icon from the left side of the IE title bar to the desktop or select a folder, a new file (. URL extension name) is created, and those links become shortcuts, so that you can send emails or share network resources.
The simplest way to look at a. URL file is to open it through notepad. The content of a network shortcut (the simplest in it) looks like this:
[Internetshortcut]
Url = http://delphi.about.com
As you can see, the. URL file has an INI file format.
The URL describes the address location of the webpage to be loaded. it must specify a completely valid URL with the Protocol format: // server/page. for more URL introduction, I suggest you read this article:
"An unofficial guide to the URL File Format"
"New..." Network shortcut
If you have a URL for the webpage you want to link to, you can easily create a network shortcut using a program. When you double-click the URL, the default browser is opened and the website content (or webpage document) is displayed in a shortcut)
Here is an example for creating. the simple Delphi function of the URL file. the createinterentshortcut function creates a URL Shortcut for a given URL (locationurl) by providing the file name, And overwrites existing network shortcuts with the same file name.
uses IniFiles;...procedure CreateInternetShortcut (const FileName, LocationURL : string);begin with TIniFile.Create(FileName) do try WriteString( 'InternetShortcut', 'URL', LocationURL); finally Free; end;end; (*CreateInterentShortcut*)
Here is the example application:
//create an .URL file named "About Delphi Programming"//in the root folder of the C drive//let it point to http://delphi.about.com CreateInterentShortcut( 'c:/About Delphi Programming.URL ', 'http://delphi.about.com ');
Note 0: You can save a webpage as an MHT (Web Archive). This is more suitable for accessing an offline web document than creating a. url shortcut.
Note 1: You must provide the filename parameter with a full path name along with the. url extension.
NOTE 2: If you already have a network shortcut, you are very interested in it. You can easily extract a URL from a network shortcut file (. url0
Icon of the specified. url
. One of the most elegant features of the URL file format is that you can change the shortcut icon. by default. the URL is associated with the icon of the default browser. If you want to change the icon, you only need. add two additional content to the URL file, as shown below:
[Internetshortcut]
Url = http://delphi.about.com
Iconindex = 0
Iconfile = C:/myfolder/mydelphiprogram.exe
Iconindex and iconfile allow you to specify the icon for the. url shortcut. iconfile can point to your EXE application file (iconindex is the index of an icon pointing to the resources of the EXE file)
Network shortcuts... open a regular document or application
Since it is called a network shortcut, you are not allowed to do other things in the. URL file format, for example, a standard application shortcut.
Note that the URL must be specified with the Protocol: // server/page. For example, you can create a network shortcut icon on the desktop and point it to your application file. You only need to specify the file: /// protocol. when you double-click. the URL file is, and your application will be executed. Here is an example:
[Internetshortcut]
Url = file: // C:/myapps/mysuperdelphiprogram.exe
Iconindex = 0
Iconfile = C:/myfolder/mydelphiprogram.exe
Here is a program used to locate the network shortcut on the desktop. The shortcut points to the * Current * application. In your program, you can use this code to create a shortcut:
uses IniFiles, ShlObj;...function GetDesktopPath: string;//get the location of the Desktop foldervar DesktopPidl: PItemIDList; DesktopPath: array [0..MAX_PATH] of Char;begin SHGetSpecialFolderLocation(0, CSIDL_DESKTOP, DesktopPidl); SHGetPathFromIDList(DesktopPidl, DesktopPath); Result := IncludeTrailingPathDelimiter(DesktopPath);end; (*GetDesktopPath*)procedure CreateSelfShortcut;const FileProtocol = 'file:///';var ShortcutTitle : string;begin ShortcutTitle := Application.Title + '.URL'; with TIniFile.Create(GetDesktopPath + ShortcutTitle) do try WriteString( 'InternetShortcut', 'URL', FileProtocol + Application.ExeName); WriteString( 'InternetShortcut', 'IconIndex', '0'); WriteString( 'InternetShortcut', 'IconFile', Application.ExeName); finally Free; end;end; (*CreateSelfShortcut*)
Note: simply call "createselfshortcut" to create a shortcut for your application on the desktop.
When to use
In my project, I am using the readily available. url files. When you create a Startup menu for your application that contains. URL File Installation Package. this allows you to conveniently access your website to update or view examples of help files.