#include <Windows.h> #include <ShlObj.h> #include <Objbase.h>

int main() { CoInitialize(NULL);

IShellLink* pShellLink = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&pShellLink);
if (SUCCEEDED(hr)) {
    IPersistFile* pPersistFile = NULL;
    hr = pShellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&pPersistFile);
    if (SUCCEEDED(hr)) {
        hr = pPersistFile->Load(L"C:\\Path\\to\\your\\file.lnk", STGM_READ);
        if (SUCCEEDED(hr)) {
            WCHAR targetPath[MAX_PATH];
            WIN32_FIND_DATA findData;
            hr = pShellLink->GetPath(targetPath, MAX_PATH, &findData, SLGP_UNCPRIORITY);
            if (SUCCEEDED(hr)) {
                // Edit or perform other operations on targetPath
                // ...

                hr = pPersistFile->Save(NULL, TRUE);
            }
        }
        pPersistFile->Release();
    }
    pShellLink->Release();
}

CoUninitialize();
return 0;

}

C++ 使用 ShellLink 对象读取和编辑 LNK 文件

原文地址: https://www.cveoy.top/t/topic/p0zf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录