Create a lnk file programmatically

In order to create an application startup shortcut on the Windows user Desktop, I know I need to create a .lnk file at c:\Document and Settings\UserName\DeskTop\ApplicationTitle.lnk
Can somebody provide the code for creating this lnk file ?
Says the title is 'ApplicationTitle', the full path to the Application is 'FullApplicationPath' and the icon should be the icon 0 of the program (Delphi program)
Who is Participating?
ZoppoConnect With a Mentor Commented:
Hi LeTay,

here's a link to a sample code to create lnk files in Delphi:

hope that helps,

Tomas Helgi JohannssonCommented:

Take a look at this example :

  Tomas Helgi
Since this is posted in C++ also, see ("Shell Links"):

// CreateLink - uses the Shell's IShellLink and IPersistFile interfaces
//              to create and store a shortcut to the specified object.
// Returns the result of calling the member functions of the interfaces.
// Parameters:
// lpszPathObj  - address of a buffer containing the path of the object.
// lpszPathLink - address of a buffer containing the path where the
//                Shell link is to be stored.
// lpszDesc     - address of a buffer containing the description of the
//                Shell link.

HRESULT CreateLink(LPCSTR lpszPathObj, LPCSTR lpszPathLink, LPCSTR lpszDesc)
    HRESULT hres;
    IShellLink* psl;
    // Get a pointer to the IShellLink interface.
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
                            IID_IShellLink, (LPVOID*)&psl);
    if (SUCCEEDED(hres))
        IPersistFile* ppf;
        // Set the path to the shortcut target and add the description.
        // Query IShellLink for the IPersistFile interface for saving the
        // shortcut in persistent storage.
        hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
        if (SUCCEEDED(hres))
            WCHAR wsz[MAX_PATH];
            // Ensure that the string is Unicode.
            MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
            // Add code here to check return value from MultiByteWideChar
            // for success.
            // Save the link by calling IPersistFile::Save.
            hres = ppf->Save(wsz, TRUE);
    return hres;
Why did you reference the C++ zone if you're not interested in a C++ solution?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.