Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Create a standard windows shortcut file
2 comments. Current rating: (1 votes). Leave comments and/ or rate it.
Q:
How can I create a standard windows shortcut file (*.lnk) from my Delphi application?
A:
Below is an example that creates a shortcut to a DOS batch file.
You need to use the procedure CreateLink();
 | |  | | program kg_MakeLink;
uses
Windows, ShlObj, ActiveX, ComObj, SysUtils, Dialogs;
procedure CreateLink(Target, Args, WorkDir, ShortCutName: String);
var
IObj: IUnknown;
Link: IShellLink;
IPFile: IPersistFile;
TargetW: WideString;
begin
IObj := CreateComObject(CLSID_ShellLink);
Link := IObj as IShellLink;
IPFile := IObj as IPersistFile;
with Link do
begin
SetPath(PChar(Target));
SetArguments(PChar(Args));
SetShowCmd(SW_SHOWMINIMIZED);
SetWorkingDirectory(PChar(WorkDir));
end;
TargetW := ShortCutName;
IPFile.Save(PWChar(TargetW), False);
end;
var
a,
b: String;
begin
if ParamCount=1 then
begin
a := ParamStr(1);
if FileExists(a) then
begin
ShowMessage('A = '+a);
b := ExtractFilename(a)+'.lnk';
ShowMessage('B = '+b);
try
CreateLink(a, '', '', ExtractFileDir(a)+#92+b);
except
halt(3);
end;
end
else
halt(2);
end
else
halt(1);
end.
| |  | |  |
Comments:
|
|
|
|
Thanks a lot
|
|
|
|
|
do you know a way to do this in java? thx a lot :-)
|
|