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)
LVL 1
LeTayAsked:
Who is Participating?
 
ZoppoConnect With a Mentor Commented:
Hi LeTay,

here's a link to a sample code to create lnk files in Delphi: http://delphi.about.com/od/windowsshellapi/a/create_lnk.htm

hope that helps,

ZOPPO
0
 
Tomas Helgi JohannssonCommented:
   Hi!

Take a look at this example : http://www.swissdelphicenter.ch/torry/showcode.php?id=317

Regards,
  Tomas Helgi
0
 
jkrCommented:
Since this is posted in C++ also, see http://msdn2.microsoft.com/en-us/library/aa969393.aspx ("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.
        psl->SetPath(lpszPathObj);
        psl->SetDescription(lpszDesc);
 
        // 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);
            ppf->Release();
        }
        psl->Release();
    }
    return hres;
}
0
 
jkrCommented:
Why did you reference the C++ zone if you're not interested in a C++ solution?
0
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.