Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[13571] Re:[질문] shellexecute로 바로가기(lnk)파일을 실행 했는데 실행 안되는 이유?
하두고 [hadugo] 2479 읽음    2011-01-25 17:38
흥군 님이 쓰신 글 :
: 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.

+ -

관련 글 리스트
11174 [질문] shellexecute로 바로가기(lnk)파일을 실행 했는데 실행 안되는 이유? 흥군 2261 2006/12/16
13571     Re:[질문] shellexecute로 바로가기(lnk)파일을 실행 했는데 실행 안되는 이유? 하두고 2479 2011/01/25
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.