흥군 님이 쓰신 글 :
: Shellexecute로 exe(실행파일)파일을 실행하면 잘되는데...
:
: 특정 PC에서 Lnk(바로가기) 파일을 실행하면 전혀 반응이 없는데...
:
:
: 혹시 이런 문제 해결하신 분 계신지요...?
:
:
: 외국 사이트까지 검색해봤는데 답이 전혀 안나오네여...
:
: 혹 아시는분 답좀 주세여~~~
오래된 질문이지만 다른 분들을 위해 답글 올립니다.
다음과 같이 하세요.
그런데 윈도우7 64BIT에서 이런 식으로 .LNK파일을 실행하면
exe파일이 Program Files (X86)폴더에 있어야 실행되네요.
다른 폴더에 있는 실행파일의 숏컷을 실행하려면 어떻게 해야 하는지
아시는 분 계시면 도움 부탁드립니다.
//=========================================================================
var
info: link_file_info;
begin
if linkfileinfo(FileName, info, False) then
begin
Result := ShellExecute(0, 'Open', info.FileName, info.Arguments, info.WorkDirectory, SW_SHOWNORMAL );
end;
//=========================================================================
// GetLNKInfo
//=========================================================================
unit GetLNKInfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,activeX, shellapi, shlobj, StdCtrls, ExtCtrls;
type
LINK_FILE_INFO = record
FileName: array[0..MAX_PATH] of char;
WorkDirectory: array[0..MAX_PATH] of char;
IconLocation: array[0..MAX_PATH] of char;
IconIndex: integer;
Arguments: array[0..MAX_PATH] of char;
Description: array[0..255] of char;
ItemIDList: PItemIDList;
RelativePath: array[0..255] of char;
ShowState: integer;
HotKey: word;
end;
function GetIconHandle(filename:string;small:Boolean =false):HIcon;
function GetIcon(filename:string;small:boolean=false):TIcon;
function linkfileinfo(const lnkfilename: string; var info: link_file_info; const bset: boolean): boolean;
implementation
function GetIconHandle(filename:string;small:Boolean=false):HIcon;
var
f:SHFILEINFO;
flag:uint;
begin
if small then flag:=SHGFI_SMALLICON
else flag:=SHGFI_LARGEICON ;
shgetfileinfo(pchar(filename),faanyfile,f,sizeof(F),flag+SHGFI_ICON);
result:=f.hIcon;
end;
function GetIcon(filename:string;small:boolean=false):TIcon;
begin
result:=ticon.create;
result.handle:=geticonhandle(filename,small);
end;
function linkfileinfo(const lnkfilename: string; var info: link_file_info; const bset: boolean): boolean;
var
hr: hresult;
psl: ishelllink;
wfd: win32_find_data;
ppf: ipersistfile;
lpw: pwidechar;
buf: pwidechar;
begin
result := false;
getmem(buf, max_path);
try
if succeeded(coinitialize(nil)) then
if (succeeded(cocreateinstance(clsid_shelllink, nil, clsctx_inproc_server, iid_ishelllinka, psl))) then
begin
hr := psl.queryinterface(ipersistfile, ppf);
if succeeded(hr) then
begin
lpw := stringtowidechar(lnkfilename, buf, max_path);
hr := ppf.load(lpw, stgm_read);
if succeeded(hr) then
begin
hr := psl.resolve(0, slr_no_ui);
if succeeded(hr) then
begin
if bset then
begin
psl.setarguments(info.arguments);
psl.setdescription(info.description);
psl.sethotkey(info.hotkey);
psl.seticonlocation(info.iconlocation, info.iconindex);
psl.setidlist(info.itemidlist);
psl.setpath(info.filename);
psl.setshowcmd(info.showstate);
psl.setrelativepath(info.relativepath, 0);
psl.setworkingdirectory(info.workdirectory);
result := succeeded(psl.resolve(0, slr_update));
end
else
begin
psl.getpath(info.filename, max_path, wfd, slgp_shortpath);
psl.geticonlocation(info.iconlocation, max_path, info.iconindex);
psl.getworkingdirectory(info.workdirectory, max_path);
psl.getdescription(info.description, 255);
psl.getarguments(info.arguments, max_path);
psl.gethotkey(info.hotkey);
psl.getidlist(info.itemidlist);
psl.getshowcmd(info.showstate);
result := true;
end;
end;
end;
end;
end;
finally
freemem(buf);
end;
end;
end.
|