Ir al contenido


Foto

Como usar IShellLink para obtener ruta de un acceso directos .lnk


  • Por favor identifícate para responder
2 respuestas en este tema

#1 JoAnCa

JoAnCa

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 775 mensajes
  • LocationPinar del Río, Cuba

Escrito 22 septiembre 2022 - 02:58

Buscando en Google encontré este ejemplo: https://stackoverflo...etwork-shortcut


delphi
  1. ShellLink := CreateComObject(CLSID_ShellLink) as IShellLink;
  2. ShellLink.QueryInterface(IPersistFile, FicheroP);
  3. PersistFile.Load('C:\Test.lnk', STGM_READ);
  4. ShellLink.Resolve(WindowHandle, 0);
  5. Filename[0] := #0;
  6. ShellLink.GetPath(PChar(@Filename[0]), Length(Filename), pfd, 0);


Pero al no estar completo, no se que tipo de variables declarar ni las unit que van en los uses

Mi objetivo final es obtener la ruta a la que apunta el acceso directo
  • 0

#2 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 23 septiembre 2022 - 02:06

Mira este código.
 


delphi
  1. uses ShlObj, ActiveX, ComObj;
  2. ...
  3.  
  4. function GetPathFromLnk(LinkFile: WideString): String;
  5. var
  6. IObject: IUnknown;
  7. ISLink: IShellLink;
  8. IPFile: IPersistFile;
  9. Path: array [0..MAX_PATH] of char;
  10. Pfd: WIN32_FIND_DATA;
  11. begin
  12. IObject := CreateComObject(CLSID_ShellLink) ;
  13. ISLink := IObject as IShellLink;
  14. IPFile := IObject as IPersistFile;
  15.  
  16. IPFile.Load(PWideChar(LinkFile), STGM_READ);
  17. Path[0] := #0;
  18. ISLink.GetPath(PChar(@Path[0]), Length(Path), Pfd, 0);
  19. Result:= Path;
  20. end;

Saludos.


  • 0

#3 JoAnCa

JoAnCa

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 775 mensajes
  • LocationPinar del Río, Cuba

Escrito 23 septiembre 2022 - 11:15

Muchas gracias, funciona perfecto
  • 0




IP.Board spam blocked by CleanTalk.