I have the following code that changes path of one shortcut. Happens that when path is changed, the icon also is updated to icon of new application.
How change path wihout update icon of shortcut?
uses
ActiveX,
ComObj,
ShlObj;
...
function GetDesktopFolder: string;
var
buf: array[0..MAX_PATH] of Char;
pidList: PItemIDList;
begin
Result := '';
SHGetSpecialFolderLocation(Application.Handle, CSIDL_DESKTOP, pidList);
if (pidList <> nil) then
if (SHGetPathFromIDList(pidList, buf)) then
Result := buf;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyObject: IUnknown;
MySLink: IShellLink;
MyPFile: IPersistFile;
LnkPath, sExePath, sParams: string;
begin
sParams := '';
sExePath := 'C:\Program Files\Google\Chrome\Application\chrome.exe';
LnkPath := GetDesktopFolder + '\Target.lnk';
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
with MySLink do
begin
SetDescription('');
SetPath(PWideChar(sExePath));
SetArguments(PWideChar(sParams));
SetWorkingDirectory(PWideChar(ExtractFilePath(sExePath)));
SetIconLocation(PWideChar(''), 0);
end;
MyPFile.Save(PWChar(WideString(LnkPath)), False);
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, PWideChar(LnkPath), nil);
end;