Reputation: 1547
I am trying to create a key in HKLM but it creates under HKLM\SOFTWARE\Wow6432Node!
as C++ builder 2010 produces 32 bit exe and it saves under 32 app section
running windows 7 x64
How to use TRegistry to do it by using flags or....
in addition OpenKeyEx
is'nt there :(
here is my code
TRegistry * reg=new TRegistry(KEY_WRITE);
try
{
reg->RootKey=HKEY_LOCAL_MACHINE;
if (!reg->OpenKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts\\UserList",0))
{
//reg->CreateKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts\\UserList");
}
//reg->Access=KEY_WRITE;
bool ores=reg->OpenKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\SpecialAccounts\\UserList",true);
reg->WriteString("ouser","0");
reg->CloseKey();
}
catch (...)
{
delete reg;
}
Upvotes: 1
Views: 1332
Reputation: 595320
You are trying to access a 64-bit Registry key from a 32-bit process. In order to do that, you need to include the KEY_WOW64_64KEY
flag when opening the key, eg:
TRegistry *reg = new TRegistry(KEY_WRITE | KEY_WOW64_64KEY);
Or:
reg->Access = KEY_WRITE | KEY_WOW64_64KEY;
In the future, if you ever upgrade to XE2 or later, which support 64-bit development, then you should specify the flag only if IsWow64Process()
reports that you are a 32-bit process running under WOW64, eg:
BOOL bIsWow64 = FALSE;
IsWow64Process(GetCurrentProcess(), &bIsWow64);
long flags = KEY_WRITE;
if (bIsWow64) flags |= KEY_WOW64_64KEY;
.
TRegistry *reg = new TRegistry(flags);
.
reg->Access = flags;
Upvotes: 4