v
How to load and read a shortcut to see where it points to
Answer:
1
2 procedure GetShellLinkInfo(const LinkFile: WideString; var SLI: TShellLinkInfo);
3 {Retrieves information on an existing shell link}
4 var
5 SL: IShellLink;
6 PF: IPersistFile;
7 FindData: TWin32FindData;
8 AStr: array[0..MAX_PATH] of char;
9 begin
10 OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink,
11 SL));
12 {The IShellLink implementer must also support the IPersistFile interface. Get an
13 interface pointer to it}
14 PF := SL as IPersistFile;
15 { Load file into IPersistFile object }
16 OleCheck(PF.Load(PWideChar(LinkFile), STGM_READ));
17 {Resolve the link by calling the Resolve interface function}
18 OleCheck(SL.Resolve(0, SLR_ANY_MATCH or SLR_NO_UI));
19 {Get all the info}
20 with SLI do
21 begin
22 OleCheck(SL.GetPath(AStr, MAX_PATH, FindData, SLGP_SHORTPATH));
23 PathName := AStr;
24 OleCheck(SL.GetArguments(AStr, MAX_PATH));
25 Arguments := AStr;
26 OleCheck(SL.GetDescription(AStr, MAX_PATH));
27 Description := AStr;
28 OleCheck(SL.GetWorkingDirectory(AStr, MAX_PATH));
29 WorkingDirectory := AStr;
30 OleCheck(SL.GetIconLocation(AStr, MAX_PATH, IconIndex));
31 IconLocation := AStr;
32 OleCheck(SL.GetShowCmd(ShowCmd));
33 OleCheck(SL.GetHotKey(HotKey));
34 end;
35 end;
|