바로가기를 클릭하면 그 바로가기의 주소를 알아내서 무조건 새창에서 실행시키는 방법을 알고 싶습니다.
프로그램 실행은 winexec 이걸로 하면 될거 같은데 주소를 어떻게 가져와야 할지 모르겠습니다.
브라우저에 정보가 넘어가는걸 잡아서 처리 해야 될거 같긴 한데요 ;;;
답변부탁드림니다.
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;
답변감사합니다.
그런데 제가 알고 싶은것은 shortCutPath 이 경로명 입니다.
바로가기는 여러가지가 만들어질수 있잔아요. 어떤 사이트에서도 만들고
개인이 만들어 등록할수도 있고요 ;;;;;;
'C:WINDOWS바탕 화면StarCraft.lnk' 이거 대신에 'C:WINDOWS바탕 화면daum.lnk'의 바로가기를
만들어서 돌려봤는데 메모장에 아무런 값도 나오질 안네요 ;;;
경로를 제가 잘못준거 같긴한데 정확하게 모르겠네요
즐프하세요...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComObj, ShlObj, ActiveX, StdCtrls;
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;
procedure TForm1.Button1Click(Sender: TObject);
var
description,
arguments,
workingDir,
iconFile : string;
hotKey : word;
showCmd,
iconIndex : integer;
begin
uoGetShortcutInfo('C:WINDOWS바탕 화면StarCraft.lnk', handle,
description, arguments, workingDir, iconFile,
hotKey, showCmd, iconIndex) ;
Memo1.Lines.Clear;
Memo1.Lines.Add( description );
Memo1.Lines.Add( arguments );
Memo1.Lines.Add( workingDir );
Memo1.Lines.Add( iconFile );
end;
end.