-1

I use CodeBlocks version 20.03 (x86) as IDE.

Here are my codes:

#include "iostream"
#include "windows.h"
using namespace std;

int main()
{
    HKEY hkRegedit;
    long longHataKodu;

    longHataKodu = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Chkdsk", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hkRegedit);

    cout << longHataKodu;

    getchar();

    return 0;
}

But the problem is even I run my program without administrator privileges, my program returns 0.

Here is the screenshot of my program:

enter image description here

How is that possible even I have written HKEY_LOCAL_MACHINE and KEY_ALL_ACCESS?

As far as I know, value 0 means ERROR_SUCCESS.

6
  • 2
    That's what RegOpenKeyEx returns when it's successful. What else do you expect it to return? Commented Sep 19, 2022 at 4:39
  • learn.microsoft.com/en-us/windows/win32/sysinfo/… Commented Sep 19, 2022 at 4:39
  • 1
    And ERROR_SUCCESS is 0. Commented Sep 19, 2022 at 5:06
  • @molbdnilo It is not possible to access HKLM with KEY_ALL_ACCESS if you do not run the program with administrator privileges. So, I think there is a bug related Codeblocks or MinGW compiler. Commented Sep 19, 2022 at 6:07
  • 1
    @ÇAĞATAYKAYA It is absolutely 100% certain that the problem is not with the IDE or the compiler, and it is possible in some cases. Did you check the details in that virtualization article? Commented Sep 19, 2022 at 7:13

1 Answer 1

0

Registry virtualization is a compatibility shim for old applications that redirects writes to HKEY_USERS\<User SID>_Classes\VirtualStore instead of causing access denied errors.

To turn it off, add a manifest to your application with a requestedExecutionLevel node to mark yourself Vista/UAC compatible.

Sign up to request clarification or add additional context in comments.

1 Comment

Adding a manifest to my application has been fixed my problem. And I think there is a little good in all evil. In this way I have learnt what "Registry Virtualization" is. I did not even know this technology until I encountered this error. Now my application throws "Access is denied." error (Error Code: 5).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.