ich verwende den folgenden Code in einer Win32-CLI-Anwendung um einen soft link zu erstellen.
Code: Alles auswählen
function CreateLink(const AFilename, ALNKFilename, ADescription: string) : Boolean;
var
psl : IShellLink;
ppf : IPersistFile;
wsz : PWideChar;
begin
result:=false;
if SUCCEEDED(CoCreateInstance(CLSID_ShellLink, nil,
CLSCTX_inPROC_SERVER, IID_IShellLinkA, psl)) then
begin
psl.SetPath(PChar(AFilename));
psl.SetDescription(PChar(ADescription));
psl.SetWorkingDirectory(PChar(ExtractFilePath(AFilename)));
if SUCCEEDED(psl.QueryInterface(IPersistFile, ppf)) then
begin
GetMem(wsz, MAX_PATH*2);
try
MultiByteToWideChar(CP_ACP, 0, PChar(ALNKFilename), -1, wsz, MAX_PATH);
ppf.Save(wsz, true);
result:=true;
finally
FreeMem(wsz, MAX_PATH*2);
end;
end;
end;
end;
OS: Win 10 64-Bit
Laz: 1.6.4 Stable
FPC: 3.0.2 Stable
Gruß
Patrick
P.S.: Falls das Problem nicht zu lösen ist, kann ich notfalls auch per ShellExecute oder TProcess "mklink.exe" aufrufen, ist aber eine nicht ganz so schöne Variante.