My code:
HKEY hKey;
char *path = "SYSTEM\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles\\0001\\HwProfileGuid";
LONG result = RegOpenKeyExA(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS, &hKey);
QString q = QString::number(result);
if (result == ERROR_SUCCESS) {
QMessageBox messageBox1;
messageBox1.critical(0,"Error", "Success");
messageBox1.setFixedSize(500,200);
} else {
QMessageBox messageBox2;
messageBox2.critical(0,"Error", q);
messageBox2.setFixedSize(500,200);
}
The error I am getting:
Where the key is in my Registry:
I think the problem is related to the way I put the info in the path
variable, but I am not sure.
You have
HwProfileGuid
in the wrong place.HwProfileGuid
is a value inside of the0001
key, but you are trying to openHwProfileGuid
as a sub-key of0001
instead, which is why you are getting error 2 (ERROR_FILE_NOT_FOUND
), because there is no sub-key namedHwProfileGuid
.Also,
KEY_ALL_ACCESS
is too many rights to request just to read a value from a key. UseKEY_QUERY_VALUE
instead. Don't request more rights than you actually need.Try this:
Alternatively, you can use
RegGetValueA()
instead of usingRegOpenKeyExA()
+RegQueryValueExA()
: