Evo, nasao sam nesto, ali, ne znam kako bih to mogao koristiti. Odnosno, kako da odradim
ono sto sam pitao pod br. 1?
Code:
function ShellLinkCreate(const Link: TShellLink; const FileName: string): HRESULT;
var
ShellLink: IShellLink;
PersistFile: IPersistFile;
LinkName: TUnicodePath;
begin
Result := CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
IID_IShellLink, ShellLink);
if Succeeded(Result) then
begin
ShellLink.SetArguments(PChar(Link.Arguments));
ShellLink.SetShowCmd(Link.ShowCmd);
ShellLink.SetWorkingDirectory(PChar(Link.WorkingDirectory));
ShellLink.SetPath(PChar(Link.Target));
ShellLink.SetDescription(PChar(Link.Description));
ShellLink.SetHotkey(Link.HotKey);
ShellLink.SetIconLocation(PChar(Link.IconLocation), Link.IconIndex);
PersistFile := ShellLink as IPersistFile;
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(FileName), -1,
LinkName, MAX_PATH);
Result := PersistFile.Save(LinkName, True);
end;
end;
Code:
function ShellLinkResolve(const FileName: string; var Link: TShellLink): HRESULT;
const
MAX_FEATURE_CHARS = 38; // maximum chars in MSI feature name
var
ShellLink: IShellLink;
PersistFile: IPersistFile;
LinkName: TUnicodePath;
Buffer: string;
Win32FindData: TWin32FindData;
FullPath: string;
ProductGuid: array [0..38] of Char;
FeatureID: array [0..MAX_FEATURE_CHARS] of Char;
ComponentGUID: array [0..38] of Char;
TargetFile: array [0..MAX_PATH] of Char;
PathSize: DWORD;
TargetResolved: Boolean;
begin
Result := CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
IID_IShellLink, ShellLink);
if Succeeded(Result) then
begin
TargetResolved := False;
// Handle MSI style shortcuts without invoking the Windows installer if
// the feature was set to "Install on first use"
if RtdlLoadMsiFuncs then
begin
FillChar(ProductGuid, SizeOf(ProductGuid), #0);
FillChar(FeatureID, SizeOf(FeatureID), #0);
FillChar(ComponentGuid, SizeOf(ComponentGuid), #0);
FillChar(TargetFile, SizeOf(TargetFile), #0);
if RtdlMsiGetShortcutTarget(PAnsiChar(FileName), ProductGuid, FeatureID, ComponentGuid) = ERROR_SUCCESS then
begin
PathSize := MAX_PATH + 1;
RtdlMsiGetComponentPath(ProductGuid, ComponentGuid, TargetFile, @PathSize);
if TargetFile <> '' then
begin
Link.Target := TargetFile;
TargetResolved := True;
end;
end;
end;
PersistFile := ShellLink as IPersistFile;
// PersistFile.Load fails if the filename is not fully qualified
FullPath := ExpandFileName(FileName);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(FullPath), -1, LinkName, MAX_PATH);
Result := PersistFile.Load(LinkName, STGM_READ);
if Succeeded(Result) then
begin
Result := ShellLink.Resolve(0, SLR_ANY_MATCH);
if Succeeded(Result) then
begin
SetLength(Buffer, MAX_PATH);
if not TargetResolved then
begin
ShellLink.GetPath(PChar(Buffer), MAX_PATH, Win32FindData, SLGP_SHORTPATH);
Link.Target := PChar(Buffer);
end;
ShellLink.GetArguments(PChar(Buffer), MAX_PATH);
Link.Arguments := PChar(Buffer);
ShellLink.GetShowCmd(Link.ShowCmd);
ShellLink.GetWorkingDirectory(PChar(Buffer), MAX_PATH);
Link.WorkingDirectory := PChar(Buffer);
ShellLink.GetDescription(PChar(Buffer), MAX_PATH);
Link.Description := PChar(Buffer);
ShellLink.GetIconLocation(PChar(Buffer), MAX_PATH, Link.IconIndex);
Link.IconLocation := PChar(Buffer);
ShellLink.GetHotkey(Link.HotKey);
ShellLink.GetIDList(Link.IdList);
end;
end;
end;
end;