0

尝试使用 IShellLink COM 接口获取 .LNK 文件的信息。它适用于许多应用程序快捷方式但对于 Microsoft Office 应用程序快捷方式它不提供正确的信息例如:

在阅读 ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office 2013\Word 2013.lnk 时

IShellLink::GetPath 返回“C:\Windows\Installer{90150000-0011-0000-0000-0000000FF1CE}\wordicon.exe”

不是 C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.exe

有什么方法可以从此类 .lnk 文件中获取目标信息。双击快捷方式时,哪个窗口用于启动应用程序。

@丹尼斯

这是我尝试过的 C++ 代码

IShellLinkDataList* comShellLinkDataList;
if (SUCCEEDED(psl->QueryInterface(IID_IShellLinkDataList,(void**)&comShellLinkDataList)))
{
    DWORD flags = 0;
    if (SUCCEEDED(comShellLinkDataList->GetFlags(&flags)))
    {
        if (flags & SLDF_HAS_DARWINID)
        {
            PIDLIST_ABSOLUTE pidList;
            if (SUCCEEDED(psl->GetIDList(&pidList)))
            {
                IShellFolder* shellFolder;
                PCITEMID_CHILD childItem;
                if (SUCCEEDED(SHBindToParent(pidList, IID_IShellFolder, (void**)&shellFolder, &childItem)))
                {
                    STRRET strRet;
                    if (SUCCEEDED(shellFolder->GetDisplayNameOf(childItem, SHGDN_NORMAL | SHGDN_FORPARSING, &strRet)))
                    {
                        TCHAR path[MAX_PATH] = {0};
                        if (SUCCEEDED(StrRetToBuf(&strRet, childItem, path, MAX_PATH)))
                        {
                            return path;
                        }
                    }                                    
                }                                
            }

        }
    }  
}
4

1 回答 1

0
function GetExeNameFromShellLink(AShellLink: IShellLink): UnicodeString;
var List: IShellLinkDataList;
    Flags: DWORD;
    IDList: PItemIDList;
    ShellFolder: IShellFolder;
    ChildItem: PItemIDList;
    Attr: DWORD;
    StrRet: TStrRet;
begin
  if Succeeded(AShellLink.QueryInterface(IShellLinkDataList, List)) then
    try
      if Succeeded(List.GetFlags(Flags)) and (Flags and SLDF_HAS_DARWINID <> 0) then
        AShellLink.Resolve(0, SLR_INVOKE_MSI);
    finally
      List := nil;
    end;
  OleCheck(AShellLink.GetIDList(IDList));
  try
    OleCheck(SHBindToParent(IDList, IShellFolder, Pointer(ShellFolder), ChildItem));
    try
      OleCheck(ShellFolder.GetDisplayNameOf(ChildItem, SHGDN_NORMAL or SHGDN_FORPARSING, StrRet));
      case StrRet.uType of
        STRRET_WSTR:
          begin
            Result := StrRet.pOleStr;
            CoTaskMemFree(StrRet.pOleStr);
          end;
        STRRET_OFFSET:
          begin
            Inc(PByte(ChildItem), StrRet.uOffset);
            Result := UnicodeString(PAnsiChar(ChildItem));
          end;
        STRRET_CSTR:
          Result := UnicodeString(AnsiString(StrRet.cStr));
      else
        Result := '';
      end;
    finally
      ShellFolder := nil;
    end;
  finally
    CoTaskMemFree(IDList);
  end;
end;
于 2014-01-18T14:38:53.327 回答