请问如何获得Office快捷方式的真实文件名?

Muf 2006-11-02 03:23:51
Office快捷方式和一般快捷方式不一样。奇怪得很。用右键属性都得不到它的文件名。
既使用程序,如word快捷方式,得到的也仅仅是wordicon.exe这种假的文件名。

Windows的哪个API或控件能真正得到office快捷方式的真实文件名呢?

---------
我用vbscript通过Shell对象获取的ShellLinkObject也一样不能得到真实文件名。
Set Shell = CreateObject("WScript.Shell")
Set lnk = Shell.CreateShortcut("c:\...\Microsoft Office Word 2003.lnk")

MsgBox(lnk.TargetPath )
MsgBox(lnk.WorkingDirectory )
MsgBox(lnk.IconLocation )
'MsgBox(lnk.RelativePath )
MsgBox(lnk.Description )
MsgBox(lnk.Hotkey )
...全文
967 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
美丽海洋 2007-01-25
  • 打赏
  • 举报
回复
~~ 没有办法 不知道
Muf 2007-01-25
  • 打赏
  • 举报
回复
现在有没有新解决方法?
Muf 2006-11-09
  • 打赏
  • 举报
回复
没办法了吗?
我暂时只能用映射的方式。如,发现是wordicon.exe就转成winword.exe出去。
美丽海洋 2006-11-03
  • 打赏
  • 举报
回复
看来这个问题 也不好解决,获得快捷方式的文件名干什么?
123ppmove 2006-11-03
  • 打赏
  • 举报
回复
up
zhucde 2006-11-03
  • 打赏
  • 举报
回复
还不如直接获取office安装目录来得快
Muf 2006-11-03
  • 打赏
  • 举报
回复
那Windows没有公开这种快捷方式的获取方法吗?
Snow_Ice11111 2006-11-02
  • 打赏
  • 举报
回复
office快捷方式是要特殊一点,如果找到上述文件名的话,就要再在注册表中找一下了:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Word\InstallRoot

下面有个Path项的值的内容就是路径了。
BOYGUARD110 2006-11-02
  • 打赏
  • 举报
回复
MARK
Muf 2006-11-02
  • 打赏
  • 举报
回复
唉,我用的正是这个方法,但是就是找不到Office快捷方式的真实文件名。
用这个方法得到的只能是wordicon.exe,xlsicon.exe这样的文件名。
Y___Y 2006-11-02
  • 打赏
  • 举报
回复
/*********************************************************************
* Function......: ResolveShortcut
* Parameters....: lpszShortcutPath - 快捷方式的路径
* lpszFilePath - 快捷方式指向的文件的路径
* Returns.......: S_OK on success, error code on failure
* Description...: Resolves a Shell link object (shortcut)
*********************************************************************/
HRESULT ResolveShortcut(/*in*/ LPCTSTR lpszShortcutPath,
/*out*/ LPTSTR lpszFilePath)
{
HRESULT hRes = E_FAIL;
CComPtr<IShellLink> ipShellLink;
// buffer that receives the null-terminated string
// for the drive and path
TCHAR szPath[MAX_PATH];
// buffer that receives the null-terminated
// string for the description
TCHAR szDesc[MAX_PATH];
// structure that receives the information about the shortcut
WIN32_FIND_DATA wfd;
WCHAR wszTemp[MAX_PATH];

lpszFilePath[0] = '\0';

// Get a pointer to the IShellLink interface
hRes = CoCreateInstance(CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void**)&ipShellLink);

if (SUCCEEDED(hRes))
{
// Get a pointer to the IPersistFile interface
CComQIPtr<IPersistFile> ipPersistFile(ipShellLink);

// IPersistFile is using LPCOLESTR,
// so make sure that the string is Unicode
#if !defined _UNICODE
MultiByteToWideChar(CP_ACP, 0, lpszShortcutPath,
-1, wszTemp, MAX_PATH);
#else
wcsncpy(wszTemp, lpszShortcutPath, MAX_PATH);
#endif

// Open the shortcut file and initialize it from its contents
hRes = ipPersistFile->Load(wszTemp, STGM_READ);
if (SUCCEEDED(hRes))
{
// Try to find the target of a shortcut,
// even if it has been moved or renamed
hRes = ipShellLink->Resolve(NULL, SLR_UPDATE);
if (SUCCEEDED(hRes))
{
// Get the path to the shortcut target
hRes = ipShellLink->GetPath(szPath,
MAX_PATH, &wfd, SLGP_RAWPATH);
if (FAILED(hRes))
return hRes;

// Get the description of the target
hRes = ipShellLink->GetDescription(szDesc,
MAX_PATH);
if (FAILED(hRes))
return hRes;

lstrcpyn(lpszFilePath, szPath, MAX_PATH);
}
}
}

return hRes;
}

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧