1

I want to disable Device Manager from my control panel editing registry values. I can do it in C#, but I want to do it in C++ without using any .NET framework. I have succedded to change my processor name in C++. But I am facing a problem when I want to disable the task manager. Here is my code.

    HKEY hKey;

    RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                 "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
                 0,
                 KEY_SET_VALUE,
                 &hKey);

    RegSetValueEx(hKey, REGNAME_TO_WRITE, 0, REG_SZ,
                  (const unsigned char *)"ProcessorNameString",
                  strlen("ProcessorNameString"));

    //RegCloseKey(hKey);

    // The problem begins here

     RegOpenKeyEx( HKEY_LOCAL_MACHINE,
                  "Software\\Policies\\Microsoft\MMC\\{74246bfc-4c96-11d0-abef-0020af6b0b7a}\\",
                  0,
                  KEY_SET_VALUE,
                  &hKey );

    RegSetValueEx( hKey,"Restrict_Run",0,REG_SZ,
                   (const unsigned char *)"1",
                   strlen("1") );

    RegCloseKey(hKey);

    return 0;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SM Farhad Ali
  • 1,063
  • 2
  • 12
  • 28
  • What version of Windows? What processor architecture? Perhaps you are running 32-bit code and changing the 32-bit view (WOW64 redirected) of the registry, but Windows is looking in the 64-bit registry. – Ben Voigt Mar 22 '12 at 18:42
  • I am using windows 7 Professional edition 32 bit. – SM Farhad Ali Mar 23 '12 at 04:18

2 Answers2

1

You should disable WOW64 registry redirection, or else your program may make changes to WOW6432Node instead of HKEY_LOCAL_MACHINE.

See Disabling registry redirection for a registry key on an x64 platform

Community
  • 1
  • 1
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Thanks for answering but what about HKEY hKey; `RegOpenKeyEx( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_SET_VALUE, &hKey ); RegSetValueEx( hKey,REGNAME_TO_WRITE,0,REG_SZ, (const unsigned char *)"ProcessorNameString", strlen("ProcessorNameString") );`This portion of code does change my processors' name perfectly. What is the problem for rest of the code. I am using windows 7 professional edition. – SM Farhad Ali Mar 23 '12 at 04:21
0

Viola, I got the solution. The solution would be like this:

DWORD dwVal = 1;

HKEY hKey = HKEY_CURRENT_USER;

RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Policies\\Microsoft\\MMC\\{74246bfc-4c96-11d0-abef-0020af6b0b7a}\\", 0, KEY_ALL_ACCESS, &hKey);

RegSetValueEx (hKey, "Restrict_Run", 0, REG_DWORD, (LPBYTE)&dwVal, sizeof(DWORD));

RegCloseKey(hKey);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SM Farhad Ali
  • 1,063
  • 2
  • 12
  • 28