由Ink文件怎样得到该Ink文件的实际Exe路径和名称?急.............有源码提供最好,在线等!!!

解决方案 »

  1.   

    MSDN例子:
    HRESULT ResolveIt(HWND hwnd, LPCSTR lpszLinkFile, LPSTR lpszPath) 

        HRESULT hres; 
        IShellLink* psl; 
        char szGotPath[MAX_PATH]; 
        char szDescription[MAX_PATH]; 
        WIN32_FIND_DATA wfd; 
     
        *lpszPath = 0; // assume failure 
     
        // Get a pointer to the IShellLink interface. 
        hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, 
                                IID_IShellLink, (LPVOID*)&psl); 
        if (SUCCEEDED(hres)) 
        { 
            IPersistFile* ppf; 
     
            // Get a pointer to the IPersistFile interface. 
            hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); 

            if (SUCCEEDED(hres)) 
            { 
                WCHAR wsz[MAX_PATH]; 
     
                // Ensure that the string is Unicode. 
                MultiByteToWideChar(CP_ACP, 0, lpszLinkFile, -1, wsz, MAX_PATH); 
     
                // TODO: Check return value from MultiByteWideChar to ensure 
                         success.
     
                // Load the shortcut. 
                hres = ppf->Load(wsz, STGM_READ); 
                
                if (SUCCEEDED(hres)) 
                { 
                    // Resolve the link. 
                    hres = psl->Resolve(hwnd, 0);                 if (SUCCEEDED(hres)) 
                    { 
                        // Get the path to the link target. 
                        hres = psl->GetPath(szGotPath, 
                                            MAX_PATH, 
                                            (WIN32_FIND_DATA*)&wfd, 
                                            SLGP_SHORTPATH);                     if (SUCCEEDED(hres)) 
                        { 
                            // Get the description of the target. 
                            hres = psl->GetDescription(szDescription, MAX_PATH);                         if (SUCCEEDED(hres)) 
                            {
                                hres = StringCbCopy(lpszPath, sizeof(lpszPath), 
                                                    szGotPath);
                                if (SUCCEEDED(hres))
                                {
                                    // Handle success
                                }
                                else
                                    // application-defined function
                                    HandleErr(hres); 
                            }
                        }
                    } 
                }             // Release the pointer to the IPersistFile interface. 
                ppf->Release(); 
            }         // Release the pointer to the IShellLink interface. 
            psl->Release(); 
        } 
        return hres; 
    }记住要先初始化组建。CoInitialize
      

  2.   

    将lnk文件的扩展名改成bin可以用UltraEdit打开,能看到目录。但要找出规律就要多试几种情况了,以前没有研究过。另外,在程序中是可以用二进制方式打开lnk,也可以读取数据。
      

  3.   

    To  idAnts(Coil & Nova Since 1985):
      你的这种方式我试过,但有Bug,你试试看,如果你打开Word的快捷方式,你就发现你打开的不是真正的Word的路径,而只是一个Wrodicon.exe的路径,所以这种方式不行!
      

  4.   

    To Snow_Ice11111(雪上加冰) :
      你的结果和idAnts(Coil & Nova Since 1985)的一样.有Bug,你试试看,如果你打开Word的快捷方式,你就发现你打开的不是真正的Word的路径,而只是一个Wrodicon.exe的路径,所以这种方式不行!