Hey Kasper,
jeg faldt lige over tråden, og håber du kommer til at se det her.
Det er testet i Delphi 7 under XP Pro SP2 og skal virke
Koden for at oprette vores genvej
function CreateShortcut(LinkPath, LinkName, ApplicationPath, Parameters, Description:string):boolean;
var
WFileName: WideString;
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
begin
WFileName:= LinkPath+'\\'+LinkName;
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
MySLink.SetPath(PChar(ApplicationPath));
MySLink.SetArguments(PChar(Parameters));
MySLink.SetDescription(PChar(Description));
MySLink.SetWorkingDirectory(PChar(ExtractFilePath(ApplicationPath)));
MyPFile.Save(PWChar(WFilename),False);
end;
Koden til at finde mappen til desktop, og andet.
function TMainForm.GetSpecialSystemPath(folder:Integer): string;
var
shellMalloc: IMalloc;
ppidl: PItemIdList;
begin
ppidl := nil;
try
if SHGetMalloc(shellMalloc) = NOERROR then
begin
SHGetSpecialFolderLocation(Handle, folder, ppidl);
SetLength(Result, MAX_PATH);
if not SHGetPathFromIDList(ppidl, PChar(Result)) then
raise exception.create('SHGetPathFromIDList failed : invalid pidl');
SetLength(Result, lStrLen(PChar(Result)));
end;
finally
if ppidl <> nil then
shellMalloc.free(ppidl);
end;
end;
Eksempel:
procedure TMainForm.Button1Click(Sender: TObject);
var link:string;
begin
link:= GetSpecialSystemPath(CSIDL_DESKTOP)+'\\';
CreateShortcut(link,'Genvej.lnk','c:\\moo.exe','','sejhed!')
end;
Indlæg senest redigeret d. 23.03.2007 19:40 af Bruger #1330