I tried to create a key in windows registry, but I got this error:
5 Access is denied.
The code snippet is like this:
HKEY hKey;
LPCTSTR sk = TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\notepad.exe"); //notepad.exe is the key I want to create
//note: if I change the first parameter to KEY_CURRENT_USER, the key will be created
LONG createResKey = RegCreateKeyEx(HKEY_LOCAL_MACHINE, sk, 0, NULL, REG_OPTION_BACKUP_RESTORE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
if (createResKey == ERROR_SUCCESS) {
qDebug() << "Success creating key.";
}
else {
qDebug() << "Error creating key.";
showErrorText(createResKey);
}
Maybe it is because my program doesn't have the admin privilege, I tried my best to do research online and tried to get the admin privilege, but failed. I am quite confused about how to solve this problem right now.
Edit: What do I want to achieve?
I am trying to block some specific apps from starting by modifying the registry. For example, if I want to block notepad, first I have to create a "notepad.exe" key, and then set a string value "debugger" to it and set its value to "debugfile.exe". So the notepad will be block from starting.