Article updated on

Crear Acceso Directo con Delphi o Lazarus Ejemplo

En este ejemplo se cubren las siguientes características:

  • Como crear un acceso directo con lazarus y ponerlo en el escritorio
  • Como sacar los directorios especiales de windows

Son necesarios los siguientes units : ShlObj, ActiveX, ComObj,  windows

  • Crea un proyecto de aplicación nuevo y añade los units.
  • Crea un formulario por defecto y botón
  • Añade el código.
procedure TForm1.Button1Click(Sender: TObject);
var
   IObject : IUnknown;
   ISLink : IShellLink;
   IPFile : IPersistFile;
   PIDL : PItemIDList;
   InFolder : array[0..MAX_PATH] of Char;
   TargetName : String;
   LinkName : WideString;
   AppDataPath: Array[0..MaxPathLen] of Char; //Allocate memory
   begin
      TargetName := 'c:\windows\notepad.exe';
      IObject := CreateComObject(CLSID_ShellLink) ;
      ISLink := IObject as IShellLink;
      IPFile := IObject as IPersistFile;
      with ISLink do
      begin
        SetPath(pChar(TargetName)) ;
        SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
        //to store the path
        AppDataPath:='';
        SHGetSpecialFolderPath(0,AppDataPath,CSIDL_DESKTOPDIRECTORY,false);
        LinkName := AppDataPath + '\Delphi Created Link.lnk';
        //to create the shortcut
        IPFile.Save(PWChar(LinkName), false) ;
      end
   end; 

 

img/0/47/Dibujo.JPG

* SHGetSpecialFolderPath Es la función que nos da la carpeta especial de windows. Pulsa Control+BotonIzquierdo del raton(en lazarus) para ver todos los directorios especiales.