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 )
既使用程序,如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 )
* 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;
}
用这个方法得到的只能是wordicon.exe,xlsicon.exe这样的文件名。
我暂时只能用映射的方式。如,发现是wordicon.exe就转成winword.exe出去。