Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
void Ctest191014Dlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
//TCHAR *lpszSubKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run222");
//LONG lRet= RegDeleteKey(HKEY_LOCAL_MACHINE, lpszSubKey);
//if (lRet == ERROR_SUCCESS) {
// MessageBox(_T("删除成功"));
//}
//else {
// MessageBox(_T("删除失败"));
//}
//HKEY hKey = NULL;
//TCHAR *lpszSubKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion");
//LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpszSubKey, 0, KEY_ALL_ACCESS, &hKey);
//if (lRet == ERROR_SUCCESS) {
// MessageBox(_T("删除成功"));
// RegDeleteKey(hKey, _T("Run333"));
//}
//else {
// MessageBox(_T("删除失败"));
//}
//删除有子键的键使用SHDeleteKey
TCHAR *lpszSubKey = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run456");
SHDeleteKey(HKEY_LOCAL_MACHINE, lpszSubKey);
}