From 6417c49b83a6384f0608a606170dfba6d716c263 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 26 Jul 2015 15:11:17 +0200 Subject: [PATCH] Added reg_key_exists() function. --- include/MUtils/Registry.h | 1 + src/Registry_Win32.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/MUtils/Registry.h b/include/MUtils/Registry.h index 8467e27..3413034 100644 --- a/include/MUtils/Registry.h +++ b/include/MUtils/Registry.h @@ -82,6 +82,7 @@ namespace MUtils MUTILS_API bool reg_value_write (const reg_root_t &rootKey, const QString &keyName, const QString &valueName, const QString &value); MUTILS_API bool reg_value_read (const reg_root_t &rootKey, const QString &keyName, const QString &valueName, quint32 &value); MUTILS_API bool reg_value_read (const reg_root_t &rootKey, const QString &keyName, const QString &valueName, QString &value); + MUTILS_API bool reg_key_exists (const reg_root_t &rootKey, const QString &keyName); MUTILS_API bool reg_key_delete (const reg_root_t &rootKey, const QString &keyName); MUTILS_API bool reg_enum_values (const reg_root_t &rootKey, const QString &keyName, QStringList &list); MUTILS_API bool reg_enum_subkeys(const reg_root_t &rootKey, const QString &keyName, QStringList &list); diff --git a/src/Registry_Win32.cpp b/src/Registry_Win32.cpp index 7c59b98..9df56db 100644 --- a/src/Registry_Win32.cpp +++ b/src/Registry_Win32.cpp @@ -340,6 +340,20 @@ bool MUtils::Registry::reg_enum_subkeys(const reg_root_t &rootKey, const QString return success; } +/* + * Check registry key existence + */ +bool MUtils::Registry::reg_key_exists(const reg_root_t &rootKey, const QString &keyName) +{ + HKEY hKey = NULL; + if(RegOpenKeyEx(registry_root(rootKey), MUTILS_WCHR(keyName), 0, STANDARD_RIGHTS_READ, &hKey) == ERROR_SUCCESS) + { + RegCloseKey(hKey); + return true; + } + return false; +} + /* * Delete registry key */