mfc 控制面板添加删除程序

只需要添加最基础的两个注册表的键即可
路径:
32位:"SOFTWAREMicrosoftWindowsCurrentVersionUninstallTest"
64位:"SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstallTest"

  1. DisplayName:显示的名称
  2. UninstallString:卸载程序路径
//写字符串
BOOL RegWriteString(HKEY hKey, string keyName, string keyValue)
{
	return RegSetValueEx(hKey, keyName.c_str(), 0, REG_SZ, (const BYTE*)keyValue.c_str(), strlen(keyValue.c_str()));
}
//添加删除
BOOL CreateUninstall(string displayName,string uninstallExePath)
{
	bool result = true;
	HKEY hKey = nullptr;
	//创建成功,将得到hKey,一个注册表句柄,用于下面操作注册表
	//_T("SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall\Test");
	//_T("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test")
	string key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Test";
	//string key = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Test";
	if (ERROR_SUCCESS != RegCreateKey(HKEY_LOCAL_MACHINE, key.c_str(), &hKey))
	{
		return false;
	}

	if (ERROR_SUCCESS != RegWriteString(hKey, "DisplayName", "测试程序"))
	{
		result= false;
	}
	if (ERROR_SUCCESS != RegWriteString(hKey,"UninstallString","c:\xxxx"))
	{
		result = false;
	}

	RegCloseKey(hKey);

	return result;
}

可选值

以下某些值将不会被旧版本的 Windows 使用。
EstimatedSize (DWORD)程序大小(单位kb)

InstallLocation (字符串)- 安装目录 ($INSTDIR)
DisplayIcon (字符串)-将要显示于你的应用程序名称旁边的图标的路径,文件名和索引。

Publisher (字符串)- 发布者(或公司)的名称

ModifyPath (字符串)- 应用程序的修复程序的路径和文件名。
InstallSource (字符串)- 应用程序的安装路径。

ProductID (字符串)- 应用程序的产品 ID。
RegOwner (字符串)- 应用程序的注册拥有者。
RegCompany (字符串)- 应用程序的注册公司。

HelpLink (字符串)- 技术支持的网站链接。
HelpTelephone (字符串)- 技术支持电话。

URLUpdateInfo (字符串)- 应用程序的在线更新网址链接。
URLInfoAbout (字符串)- 应用程序的主页链接。

DisplayVersion (字符串)- 应用程序的显示版本。
VersionMajor (DWORD)- 应用程序的主版本号。
VersionMinor (DWORD)- 应用程序的副版本号。

NoModify (DWORD)- 1 (如果卸载程序没有修改应用程序的选项)
NoRepair (DWORD)- 1 (如果卸载程序没有修复安装程序的选项)

如果“NoModify”和“NoRepair”都被设为 1,那么按钮将会用“删除”代替“修改/删除”。

参考

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