Search code examples
c++registry

Unable to create a new registry after a certain point in the structure


Hi,

I am currently trying to create an application that can disable/enable the options from the ctrl+alt+del menu in windows 7.

This is a snippet of code, it's hardcoded to remove the Task Manager:

HKEY hkey;
DWORD dwDisposition;
bool ok = false;
if (RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"), 0, NULL, 0, KEY_WRITE, NULL, &hkey, &dwDisposition) == ERROR_SUCCESS) {
    DWORD rofl = 1;
    if (RegSetValueEx(hkey, TEXT("DisableTaskMgr"), 0, REG_DWORD, (PBYTE)&rofl, sizeof(DWORD)) == ERROR_SUCCESS){
        ok = true;
    }
    RegCloseKey(hkey);
}

For example, if I try to create this registry in HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion or any other folder, everything works fine. But as soon as I try to enter Policies, the RegCreateKeyEx function does not return ERROR_SUCCES.

Since, that's the location where I need to put that registry in order to remove Task Manager option, I'm wondering why can't I acces that folder?

PS If I run the following reg file, the registry is created and the Task Manager option is removed, so I'm guessing I have the necessary rights:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System]"DisableTaskMgr"=dword:00000001

Solution

  • The function call (with these exact parameters) returns code 5 which stands for insufficient permissions (ERROR_ACCESS_DENIED), as you have guessed yourself. Try running the application as administrator if you haven't already.