Board index » delphi » How can i create shortcut to a file with delphi

How can i create shortcut to a file with delphi

Im trying to create a shortcut to my exe file, in desktop within delphi.
Is there a function that creates a shortcut in delphi?

Mert

 

Re:How can i create shortcut to a file with delphi


On Wed, 4 Jul 2001 18:49:56 +0300, "Mert Sakarya" <mertsaka...@webokul.com>
wrote:

Quote
>Im trying to create a shortcut to my exe file, in desktop within delphi.
>Is there a function that creates a shortcut in delphi?

>Mert

Hi Mert.  Look in the online help for Shell Link.
Also there are some freewares on
http://homepages.borland.com/torry/

that make it easy to mess with links(shortcuts)

Mike

--

"Only choice is an oxymoron."

--

Re:How can i create shortcut to a file with delphi


Hi,

There is no single API call to create a shortcut. You would rather have to
use IShellLink OLE interface for this purpose. Check the following sample
code:

uses
  Windows, Ole2, ShlObj, SysUtils, Forms;

procedure CreateLink(ObjectPath: string;
// path of the file/folder to create a shortcut
                                         LinkPath: string;
// path of the newly created link/shortcut
                     Description : string);
var  ShellLink   : IShellLink;
var  PersistFile : IPersistFile;
var  WidePath    : array[0..259] of WideChar;
begin
  // initialize COM library
  CoInitialize;
  // Get a pointer to the IShellLink interface.
  if Failed(CoCreateInstance(CLSID_ShellLink,nil,CLSCTX_INPROC_SERVER,
                    IID_IShellLink,ShellLink)) then
         raise Exception.Create('Unable to create an IShellLink instance');
  try
        // set the path to the shortcut target
        ShellLink.SetPath(PChar(ObjectPath));
        // set the Link description
        ShellLink.SetDescription(PChar(Description));
        // Query IShellLink for the IPersistFile interface for saving the
        // shortcut in persistent storage.
        if Failed(ShellLink.QueryInterface(IID_IPersistFile,PersistFile)) then
                raise Exception.Create('Unable to create an IPersistFile instance');
        try
                // ensure that the string is ANSI.
                MultiByteToWideChar(CP_ACP, 0, PChar(LinkPath), -1,WidePath, 259);
                // save the link by calling IPersistFile::Save.
                if Failed(PersistFile.Save(WidePath, TRUE)) then
                        raise Exception.Create('Unable to save link');
        finally
                // free the IPersistFile interface
                PersistFile.Release;
        end;
    // unitialize COM library
    CoUninitialize;
  finally
        // free the IShellLink interface
        ShellLink.Release;
  end;
end;

If you want to create your shortcut in a "special" directory, check the
WinAPI helpfile for a description of the ShGetSpecialFolderLocation()
function.

Thanks & regards,

Karthi keyan V
Technical Consultant,
Botreesoft, Chennai.
INDIA.
Office: 91-44-4982862.
Mobile : 98400 66440
official : kart...@botree.co.in
www.botree.co.in
Let's make IT happen.

Quote
"Mert Sakarya" <mertsaka...@webokul.com> wrote in message

news:3b433a62_1@dnews...
Quote
> Im trying to create a shortcut to my exe file, in desktop within delphi.
> Is there a function that creates a shortcut in delphi?

> Mert

Other Threads