RegOpenKey / RegOpenKeyEx returns 2 (file not found) on Windows 7, while key exists

StackOverflow https://stackoverflow.com/questions/9533765

  •  03-12-2019
  •  | 
  •  

Вопрос

I am trying to read a value from HKEY_CURRENT_USER\Software\Classes on Windows 7 as a standard user, and although the key exists, I get an error. Both codes below don't success:

l = RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Classes", 0, KEY_READ, &hKey);

// RegOpenKeyEx doesn't success either
l = RegOpenKey(HKEY_CURRENT_USER, L"Software\\Classes", &hKey);

This code is located in a dll called by an application doing many things (I don't know all that it does).

However, a simple app with just RegOpenKey on the same computer with the same account works perfectly...

Can anyone tell me what could cause the problem and the differences between the two? The test app is written in c++, while the dll is written in c.

EDIT: Problem solved, by just removing the "L" before L"Software\Classes"...

Это было полезно?

Решение 2

I solved the problem by passing "Software\Classes" instead of L"Software\Classes" to the function.

Другие советы

Likely, the code is running as a different user or its current user isn't in synch with the cached registry key for the process. See RegOpenCurrentUser.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top