#include#include // create a shell link object IShellLink *link; CoInitialize(NULL); CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&link)); // set the path and description for the shell link link->SetPath(L"C:\\Program Files\\MyApp\\MyApp.exe"); link->SetDescription(L"MyApp"); // save the shell link to a file IPersistFile *file; link->QueryInterface(IID_PPV_ARGS(&file)); file->Save(L"C:\\users\\myuser\\Desktop\\MyApp.lnk", TRUE); file->Release(); link->Release();
#includeThis code gets the target path for a shell link and prints it out. Package library: shell32.lib#include // get the target path for a shell link wchar_t path[MAX_PATH]; CoInitialize(NULL); IShellLink *link = NULL; IPersistFile *file = NULL; CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&link)); file = (IPersistFile*) link; if (file->Load(L"C:\\users\\myuser\\Desktop\\MyApp.lnk", STGM_READ) == S_OK) { link->GetPath(path, MAX_PATH, NULL, 0); printf("Target path is: %ls\n", path); } file->Release(); link->Release();