바탕화면에 바로가기 파일을 만들고 나서..
바탕화면 바로가기 파일을 검색한후 바로가기 파일이 없으면 생성하려고 합니다. 그런데 바로가기 이름을 바꾸면 찾지 못하여. 바로가기 파일의 실행파일 경로를 구해 프로그램 실행 파일과 비교하여 없으면 바로가를 생성하고 싶습니다. 그런데 실행파일 경로를 알지 못해서....
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function uoGetShortcutInfo(const shortCutPath: string; aHWnd: HWnd;
var description, arguments, workingDir, iconFile: string;
var hotKey: word; var showCmd, iconIndex: integer): string;
// Given the full path to a shortcut (typically something like
// c:windowsdesktopsomething.lnk), returns all of the info about
// that shortcut.
var
hRes: longInt;
aISL: IShellLink;
aIPF: IPersistFile;
wfd: TWin32FindData;
shortCutPathW: WideString;
begin
result := ''; // Fall-through value
// Get a pointer to the IShellLink interface.
hres := CoCreateInstance(CLSID_ShellLink, nil,
CLSCTX_INPROC_SERVER, IID_IShellLinkA, aISL);
if (SUCCEEDED(hres)) then
begin
// Get a pointer to the IPersistFile interface.
aIPF := (aISL as IPersistFile);
if assigned(aIPF) then
begin
shortCutPathW := shortCutPath;
// Load the shortcut
hres := aIPF.Load(PWideChar(shortCutPathW), STGM_READ);
if SUCCEEDED(hres) then
begin
// Resolve the link.
if (aHWnd = $FFFFFFFF) then // -1 means no UI wanted
hres := aISL.Resolve(aHWnd, SLR_NO_UI)
else // Windows search dialog will appear if necessary
hres := aISL.Resolve(aHWnd, SLR_ANY_MATCH);
if SUCCEEDED(hres) then
begin
// Get the path to the link target.
SetLength(result, MAX_PATH);
hres := aISL.GetPath(PChar(result),
MAX_PATH, wfd,
SLGP_SHORTPATH );
if (not SUCCEEDED(hres)) then
begin
// We didn't get the path. Reset the length of result
SetLength(result, 0)
end
else
begin
// Set the correct length in the path
SetLength(result, strLen(PChar(result)));
// Now, on to the other information
// The description
SetLength(description, MAX_PATH);
hres := aISL.GetDescription(PChar(description), MAX_PATH);
if SUCCEEDED(hres) then
SetLength(description, strLen(PChar(description)))
else
SetLength(description, 0);
// If the interface didn't give us a description, use the title
// of the link itself
if (length(description) = 0) then
begin
description := ExtractFileName(shortCutPath);
description := ChangeFileExt(description, '');
end;
// The working directory
SetLength(workingDir, MAX_PATH);
hres := aISL.GetWorkingDirectory(PChar(workingDir), MAX_PATH);
if SUCCEEDED(hres) then
SetLength(workingDir, strLen(PChar(workingDir)))
else
SetLength(workingDir, 0);
// The arguments
SetLength(arguments, MAX_PATH);
hres := aISL.GetArguments(PChar(arguments), MAX_PATH);
if SUCCEEDED(hres) then
SetLength(arguments, strLen(PChar(arguments)))
else
SetLength(arguments, 0);
// The icon file and index
SetLength(iconFile, MAX_PATH);
hres := aISL.GetIconLocation(PChar(iconFile), MAX_PATH, iconIndex);
if SUCCEEDED(hres) then
SetLength(iconFile, strLen(PChar(iconFile)))
else
SetLength(iconFile, 0);
// The SHOWCOMMAND
aISL.GetShowCmd(showCmd);
// The hotkey
aISL.GetHotkey(hotKey);
end;
end;
end;
end;
end;
end;
function ExtractFileDir(const FileName: string): string;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(ExtractFilePath(ParamStr(0)));
end;