바탕화면이나 시작 메뉴에 있는 '뿅뿅의 바로가기' 파일에서 정보를 몽땅 받아오는 팁.
리스트뷰에 출력하며 해당 실행파일의 아이콘까지 출력.
uses 에 ShlObj, ActiveX, ComObj, CommCtrl, ShellApi, ShFolder 추가하고
요런 구조체를 하나 정의하고
// lnk 구조체
type
PShellLinkInfoStruct=^TShellLinkInfoStruct;
TShellLinkInfoStruct=record
FullPathAndNameOfLinkFile: array [0..MAX_PATH] of Char;
FullPathAndNameOfFileToExecute: array [0..MAX_PATH] of Char;
ParamStringsOfFileToExecute: array [0..MAX_PATH] of Char;
FullPathAndNameOfWorkingDirectory: array [0..MAX_PATH] of Char;
Description: array [0..MAX_PATH] of Char;
FullPathAndNameOfFileContainingIcon: array [0..MAX_PATH] of Char;
IconIndex: Integer;
HotKey: WORD;
ShowCommand: Integer;
FindData: TWIN32FINDDATA;
end;
type
PShellLinkInfoStruct=^TShellLinkInfoStruct;
TShellLinkInfoStruct=record
FullPathAndNameOfLinkFile: array [0..MAX_PATH] of Char;
FullPathAndNameOfFileToExecute: array [0..MAX_PATH] of Char;
ParamStringsOfFileToExecute: array [0..MAX_PATH] of Char;
FullPathAndNameOfWorkingDirectory: array [0..MAX_PATH] of Char;
Description: array [0..MAX_PATH] of Char;
FullPathAndNameOfFileContainingIcon: array [0..MAX_PATH] of Char;
IconIndex: Integer;
HotKey: WORD;
ShowCommand: Integer;
FindData: TWIN32FINDDATA;
end;
위에 정의한 구조체를 파라메터로 받아서 해당 바로가기 파일의 정보를 박아넣는 함수
// lnk 구조체에 해당 정보를 박아 넣기
////////////////////////////////////////////////////////////////////////////////
procedure GetLinkInfo(lpShellLinkInfoStruct: PShellLinkInfoStruct);
var
ShellLink: IShellLink;
PersistFile: IPersistFile;
AnObj: IUnknown;
////////////////////////////////////////////////////////////////////////////////
procedure GetLinkInfo(lpShellLinkInfoStruct: PShellLinkInfoStruct);
var
ShellLink: IShellLink;
PersistFile: IPersistFile;
AnObj: IUnknown;
begin
AnObj:=CreateComObject(CLSID_ShellLink);
ShellLink:=AnObj as IShellLink;
PersistFile:=AnObj as IPersistFile;
AnObj:=CreateComObject(CLSID_ShellLink);
ShellLink:=AnObj as IShellLink;
PersistFile:=AnObj as IPersistFile;
PersistFile.Load(PWChar(WideString(lpShellLinkInfoStruct^.FullPathAndNameOfLinkFile)), 0);
with ShellLink do begin
// 실행파일 경로
GetPath(lpShellLinkInfoStruct^.FullPathAndNameOfFileToExecute,
SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfLinkFile),
lpShellLinkInfoStruct^.FindData,
SLGP_UNCPRIORITY);
// 실행파일 경로
GetPath(lpShellLinkInfoStruct^.FullPathAndNameOfFileToExecute,
SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfLinkFile),
lpShellLinkInfoStruct^.FindData,
SLGP_UNCPRIORITY);
// 설명
GetDescription(lpShellLinkInfoStruct^.Description,
SizeOf(lpShellLinkInfoStruct^.Description));
GetDescription(lpShellLinkInfoStruct^.Description,
SizeOf(lpShellLinkInfoStruct^.Description));
// 실행파라메터
GetArguments(lpShellLinkInfoStruct^.ParamStringsOfFileToExecute,
SizeOf(lpShellLinkInfoStruct^.ParamStringsOfFileToExecute));
GetArguments(lpShellLinkInfoStruct^.ParamStringsOfFileToExecute,
SizeOf(lpShellLinkInfoStruct^.ParamStringsOfFileToExecute));
// 디렉토리
GetWorkingDirectory(lpShellLinkInfoStruct^.FullPathAndNameOfWorkingDirectory,
SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfWorkingDirectory));
GetWorkingDirectory(lpShellLinkInfoStruct^.FullPathAndNameOfWorkingDirectory,
SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfWorkingDirectory));
// 아이콘
GetIconLocation(lpShellLinkInfoStruct^.FullPathAndNameOfFileContainingIcon,
SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfFileContainingIcon),
lpShellLinkInfoStruct^.IconIndex);
GetIconLocation(lpShellLinkInfoStruct^.FullPathAndNameOfFileContainingIcon,
SizeOf(lpShellLinkInfoStruct^.FullPathAndNameOfFileContainingIcon),
lpShellLinkInfoStruct^.IconIndex);
// 핫키
GetHotKey(lpShellLinkInfoStruct^.HotKey);
GetHotKey(lpShellLinkInfoStruct^.HotKey);
// 커맨드
GetShowCmd(lpShellLinkInfoStruct^.ShowCommand);
end;
end;
////////////////////////////////////////////////////////////////////////////////
GetShowCmd(lpShellLinkInfoStruct^.ShowCommand);
end;
end;
////////////////////////////////////////////////////////////////////////////////
사용할 때는 이런식으로 사용하면 됨.
procedure ShowLnk;
var
LinkInfo: TShellLinkInfoStruct;
s: String;
var
LinkInfo: TShellLinkInfoStruct;
s: String;
begin
// 구조체 초기화
FillChar(LinkInfo, SizeOf(LinkInfo), #0);
// 구조체 초기화
FillChar(LinkInfo, SizeOf(LinkInfo), #0);
LinkInfo.FullPathAndNameOfLinkFile:='C:\Document and Settings\Administrator\바탕 화면\뿅뿅.lnk';
// .lnk 파일 정보를 구조체에 저장
GetLinkInfo(@LinkInfo);
GetLinkInfo(@LinkInfo);
// 스트링에 해당 정보를 박아넣고
with LinkInfo do begin
s:=FullPathAndNameOfLinkFile+#13#10+
FullPathAndNameOfFileToExecute+#13#10+
ParamStringsOfFileToExecute+#13#10+
FullPathAndNameOfWorkingDirectory+#13#10+
Description+#13#10+
FullPathAndNameOfFileContainingIcon+#13#10+
IntToStr(IconIndex)+#13#10+
IntToStr(LoByte(HotKey))+#13#10+
IntToStr(HiByte(HotKey))+#13#10+
IntToStr(ShowCommand)+#13#10+
FindData.cFileName+#13#10+
FindData.cAlternateFileName;
end;
with LinkInfo do begin
s:=FullPathAndNameOfLinkFile+#13#10+
FullPathAndNameOfFileToExecute+#13#10+
ParamStringsOfFileToExecute+#13#10+
FullPathAndNameOfWorkingDirectory+#13#10+
Description+#13#10+
FullPathAndNameOfFileContainingIcon+#13#10+
IntToStr(IconIndex)+#13#10+
IntToStr(LoByte(HotKey))+#13#10+
IntToStr(HiByte(HotKey))+#13#10+
IntToStr(ShowCommand)+#13#10+
FindData.cFileName+#13#10+
FindData.cAlternateFileName;
end;
// 메모장에 출력
Form1.Memo1.Lines.Add(s);
end;
Form1.Memo1.Lines.Add(s);
end;
'Delphi' 카테고리의 다른 글
[Delphi] 커서 바꾸기 (1) | 2009.04.18 |
---|---|
[Delphi] 프로세스 리스트 (0) | 2009.04.18 |
BDS Error List (0) | 2009.04.18 |
[Delphi] Boolean Types (0) | 2009.04.18 |
[Delphi] System Common Util 함수들 (0) | 2009.04.18 |