function GetDesktopFolder: string;
var
buf: array[0..MAX_PATH] of Char;
pidList: PItemIDList;
begin
Result := StrNoDesktopFolderFo;
SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, pidList);
if (pidList <> nil) then
if (SHGetPathFromIDList(pidList, buf)) then
Result := buf;
end;
procedure p;
var
i: Integer;
IObject: IUnknown;
ISLink: IShellLink;
IPFile: IPersistFile;
PIDL: PItemIDList;
InFolder: array[0..MAX_PATH] of Char;
TargetName: string;
LinkName: string;
begin
TargetName := 'c:\folder\exeFile.exe';//hardcoded example
IObject := CreateComObject(CLSID_ShellLink) ;
ISLink := IObject as IShellLink;
IPFile := IObject as IPersistFile;
with ISLink do
begin
SetDescription('what ever');
SetPath(pChar(TargetName)) ;
SetWorkingDirectory(pChar(ExtractFilePath(TargetName))) ;
end;
SHGetSpecialFolderLocation(0, CSIDL_DESKTOPDIRECTORY, PIDL) ;
SHGetPathFromIDList(PIDL, InFolder) ;
LinkName := getDesktopFolder+'\';
i := ;
LinkName:= linkname+ExtractFileName(TargetName)+'.lnk';
if LinkName = StrNoDesktopFolderFo then
Exit;
if not FileExists(LinkName) then
IPFile.Save(PWChar(LinkName), False);
Application.Terminate;
end;
El código anterior hace que una gran cantidad de errores en Delphi y no puede correr el doble ...Cómo crear un acceso directo a archivos (archivo * .lnk) en el escritorio en Windows?
¿Alguna idea?
Btw. la fuente no es originalmente mía, fue recogida de lugares en la web.
no es el problema, pero las matrices deben ser 0..MAX_PATH-1 –