mfc 创建桌面快捷方式&删除

/// <summary>
/// 删除快捷方式
/// </summary>
/// <param name="strName"></param>
/// <returns></returns>
BOOL DeleteDesktopShotCut(CString strName) {
	char Path[MAX_PATH + 1];
	CString strDestDir;
	int i = CSIDL_DESKTOPDIRECTORY;
	LPITEMIDLIST pidl;
	LPMALLOC pShell;
	if (SUCCEEDED(SHGetMalloc(&pShell)))
	{
		if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, i, &pidl)))
		{
			if (!SHGetPathFromIDList(pidl, Path))
			{
				pShell->Free(pidl);
				::CoUninitialize();
				return FALSE;
			}
			pShell->Release();
			strDestDir.Format("%s", Path);
			strDestDir += "\";
			strDestDir += strName;//设置桌面快捷方式的名字
			strDestDir += ".lnk";

			DeleteFile(strDestDir);
		}
	}
}

BOOL CreateUninstall(string displayName, string uninstallExePath, string modifyPath,
	string displayVersion,
	string icoPath, string installPath, string publisher, string company, string helpLink,
	string helpTelephone, string urlInfoAbout)
{
	bool result = true;
	HKEY hKey = nullptr;
	string key = GetUninstallKey() + displayName;
	//string key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + displayName;
	//string key = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Test";
	if (ERROR_SUCCESS != RegCreateKey(HKEY_LOCAL_MACHINE, key.c_str(), &hKey))
	{
		return false;
	}

	//先创建可选项(不影响必选项创建结果)
	result = (ERROR_SUCCESS == RegWriteString(hKey, "DisplayVersion", displayVersion));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "DisplayIcon", icoPath));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "Publisher", publisher));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "RegCompany", company));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "HelpLink", helpLink));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "HelpTelephone", helpTelephone));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "URLInfoAbout", urlInfoAbout));
	result = (ERROR_SUCCESS == RegWriteString(hKey, "InstallLocation", installPath));
	/*if (modifyPath != "") {
		string modifyStr = modifyPath + " " + CONST_UPGRADE;

		result = (ERROR_SUCCESS == RegWriteString(hKey, "ModifyPath", modifyStr));
	}*/


	//必选项
	result = (ERROR_SUCCESS == RegWriteString(hKey, "DisplayName", displayName, false));

	if (uninstallExePath != "") {
		string uninstallStr = uninstallExePath + " " + CONST_UNINSTALL;
		result = (ERROR_SUCCESS == RegWriteString(hKey, "UninstallString", uninstallStr, false));
	}



	//EstimatedSize
	RegCloseKey(hKey);

	return result;
}

留待后查,同时方便他人
联系我:renhanlinbsl@163.com
原文地址:https://www.cnblogs.com/ives/p/14900141.html