Vista

Vista Does Not Virtualize Creation Of Shell Links

Vista Does Not Virtualize Creation Of Shell Links

Windows Vista developers beware: Vista does not perform file virtualization on the creation of shell links. Consider the following code: // Creates a shell link (a.k.a. shortcut) located at swzLinkFile that points to // szTargetFile with a description of szDescription. BOOL CreateLink(LPCTSTR szTargetFile, LPCTSTR szDescription, LPCOLESTR swzLinkFile) { BOOL bRet = FALSE; IShellLink* psl; HRESULT hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**) &psl); if (SUCCEEDED(hr)) { IPersistFile* ppf; hr = psl->QueryInterface(IID_IPersistFile, (void**) &ppf); if (SUCCEEDED(hr)) { hr = psl->SetPath(szTargetFile); if (SUCCEEDED(hr)) { hr = psl->SetDescription(szDescription); if (SUCCEEDED(hr)) { hr = ppf->Save(swzLinkFile, TRUE); if (SUCCEEDED(hr)) { bSuccess = TRUE; } } } ppf->Release(); } psl->Release(); } return bSuccess; } // NOTE: Hardcoding C:\WINDOWS and C:\Program Files is a bad practice.