windows中判断注册表键值是否存在的一段函数

来源:互联网 发布:集成式网络部署 编辑:程序博客网 时间:2024/05/10 12:10

下面这个函数用于判断注册表键值是否存在

bool IsRegValueExisted(HKEY hMainKey, LPCTSTR pSubKey, LPCTSTR pValName){bool bRet =false;DWORD dwType = REG_SZ;HKEY hKey;LSTATUS nRes = RegOpenKeyEx(hMainKey, pSubKey, 0, KEY_READ,  &hKey);if (nRes != ERROR_SUCCESS) {return false;}nRes = RegQueryValueEx(hKey, pValName, NULL, &dwType, NULL, NULL);RegCloseKey(hKey);if (nRes == ERROR_SUCCESS || nRes ==ERROR_MORE_DATA) {bRet = true;}return bRet;}


调用方式像这样

IsRegValueExisted(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), _T("CCUI")



原创粉丝点击