1.快捷方式名称的修改
QDir dir(QDir::homePath() + "/Desktop");
QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files);
foreach(QFileInfo fileInfo, fileInfoList)
{
if(fileInfo.isSymLink() && fileInfo.symLinkTarget() ==
QDir::currentPath() + "/AlarmClientSys.exe")
{
QFile::rename(fileInfo.absoluteFilePath(), fileInfo.absolutePath() + "/" + systemName + ".lnk");
break;
}
}
2. 快捷方式图标的修改
(1)替换快捷方式关联的图标文件
(2) 调用 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
3. 修改快捷方式图标的方法
bool ChangeLinkIcon(LPCOLESTR strLnkName, LPCSTR strIconPath)
{
if(0 == strLnkName || 0 == strIconPath) return false;
HRESULT hres;
IShellLink *psl = NULL;
IPersistFile *pPf = NULL;
bool bRet = false;
do
{
hres = CoInitialize(NULL);
if (FAILED(hres))
{
break;
}
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (FAILED(hres))
{
break;
}
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&pPf);
if (FAILED(hres))
{
break;
}
hres = pPf->Load(strLnkName, STGM_READWRITE);
if (FAILED(hres))
{
break;
}
hres = psl->SetIconLocation(strIconPath, 0);
if (FAILED(hres))
{
break;
}
pPf->Save(strLnkName, TRUE);
if (FAILED(hres))
{
break;
}
bRet = true;
} while (0);
if (pPf != NULL)
{
pPf->Release();
}
if (psl != NULL)
{
psl->Release();
}
CoUninitialize();
return bRet;
}