-
September 25th, 2015, 01:22 AM
#1
Can read REG_SZ but not REG_DWORD value
Hi,
I can read REG_SZ values but not REG_DWORD values from the registry.
Do I need another type than char* as 5th parameter of the RegQueryValueEx() function if I want to read REG_DWORD value
or something else is the problem?
Code:
#include <windows.h>
#include <winreg.h>
#include <iostream>
using namespace std;
int main()
{
HKEY hKey;
char Data[255];
DWORD Datasize = sizeof(Data);
DWORD Type;
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
0,
KEY_QUERY_VALUE|KEY_WOW64_32KEY,
&hKey)== ERROR_SUCCESS)
{
DWORD error = RegQueryValueEx(hKey,
"InstallDate",
NULL,
&Type,
(LPBYTE)&Data,
&Datasize);
if(error == ERROR_SUCCESS)
{
cout << " Data = " << Data <<
"\n Size = " << Datasize <<
"\n Type = " << Type <<endl;
}
else
{
cout << "RegQueryValueEx error " << error << endl;
}
}
else cout << "RegopenkeyEx error " << error << endl;
RegCloseKey(hKey);
return 0;
}
-
September 25th, 2015, 02:48 AM
#2
Re: Can read REG_SZ but not REG_DWORD value
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 25th, 2015, 04:32 AM
#3
Re: Can read REG_SZ but not REG_DWORD value
Thank you Kaud!
I managed to read other REG_DWORD values by modifying the code with the help of your link but this specific key returns me 0.
Edit: but on another machine its working so it must be something else than the code.
Last edited by MasterDucky; September 25th, 2015 at 06:34 AM.
-
September 27th, 2015, 01:47 PM
#4
Re: Can read REG_SZ but not REG_DWORD value
Check out the CRegKey class in msdn - all that registry stuff is done for you.
-
September 28th, 2015, 02:21 AM
#5
Re: Can read REG_SZ but not REG_DWORD value
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|