Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Registry read/write on Win32 vs Win64



Permlink Replies: 10 - Last Post: Aug 24, 2016 12:00 PM Last Post By: Remy Lebeau (Te...
Bo Berglund

Posts: 757
Registered: 10/23/02
Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 4:30 AM
I have to create a configuration program for an old 32 bit legacy
application we are still using extensively.
Its own configurator is a Control Panel applet (cpl), which refuses to
start in recent Windows versions.

All of the config data reside in the Windows Registry and during my
tests I found out that if install the application on say Windows 7 x64
and migrate the registry keys from a working installation (on Windows
Server 2003 32 bit), then it won't work properly.
After some extensive testing I found that the application actually
reads from (and presumably writes to) the same key as expected but
located below HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...

So I figured that I could create a configuration program in Delphi XE5
which should work towards the key above.

Question:
Is there something special I have to look out for concerning the
registry read/write in order to produce data readable by the old legacy
application?
Do I specifically use the key above in my configurator or is there some
switch in the registry handling I need to activate?

Note that on a 32 bit platform I do not think that the Wow6432Node key
exists and still I need my configurator to be able to handle both 32
and 64 bit platforms from the 32 bit Delphi XE5 program.

--

Bo Berglund
Sweden & Texas
now using XanaNews 1.20-0cfde51
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 4:55 AM   in response to: Bo Berglund in response to: Bo Berglund
El 23/08/2016 a las 13:30, Bo Berglund escribió:
I have to create a configuration program for an old 32 bit legacy
application we are still using extensively.
Its own configurator is a Control Panel applet (cpl), which refuses to
start in recent Windows versions.

All of the config data reside in the Windows Registry and during my
tests I found out that if install the application on say Windows 7 x64
and migrate the registry keys from a working installation (on Windows
Server 2003 32 bit), then it won't work properly.
After some extensive testing I found that the application actually
reads from (and presumably writes to) the same key as expected but
located below HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...

So I figured that I could create a configuration program in Delphi XE5
which should work towards the key above.

Question:
Is there something special I have to look out for concerning the
registry read/write in order to produce data readable by the old legacy
application?
Do I specifically use the key above in my configurator or is there some
switch in the registry handling I need to activate?

Note that on a 32 bit platform I do not think that the Wow6432Node key
exists and still I need my configurator to be able to handle both 32
and 64 bit platforms from the 32 bit Delphi XE5 program.

If the configuration program is a Win32 application, you do not have to worry about anything. Write the information to
the original key used by the legacy application (without Wow6432Node in the key path). In Windows x64, the OS will
redirect the key transparently to the right path.
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 6:01 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:

If the configuration program is a Win32 application, you do not have
to worry about anything. Write the information to the original key
used by the legacy application (without Wow6432Node in the key path).
In Windows x64, the OS will redirect the key transparently to the
right path.

Is there a difference between HKCU and HKLM in this respect?
When I look in my Win7 x64 computer's registry under HKCU/Software I
find the Wow6432Node node there but no entries except from Microsoft
below it.
Specifically my own 32 bit applications which write to
HKCU/Software/Company... etc seem to stuff the data into the regular
place where they also can retrieve them.

OTOH in HKLM I see a fair number of entries below Wow6432Node.

In the current case the config data go to HKLM but what I found with
the legacy app is that it reads from HKLM/Software/Wow6432Node/...

So if my Delphi 32 bit applications just write to the registry and do
not themselves go to the Wow6432Node I am hosed concerning the config
app, it must write the data to the Wow6432Node if it runs on a 64 bit
system but not if it runs on a 32 bit system...

--

Bo Berglund
Sweden & Texas
now using XanaNews 1.20-0cfde51
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 7:30 AM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:

[snim]

Google and MSDN are your friends. For example:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.8
5).aspx. Have a nice time reading it.
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 7:36 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos Juhasz wrote:

Bo Berglund wrote:

[snim]

Google and MSDN are your friends. For example:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724072(v=vs.8
5).aspx. Have a nice time reading it.

I have already read it but did not find it useful in my Delphi
setting...

--

Bo Berglund
Sweden & Texas
now using XanaNews 1.20-0cfde51

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 2:17 PM   in response to: Bo Berglund in response to: Bo Berglund
Bo wrote:

Is there a difference between HKCU and HKLM in this respect?

Yes. Read the documentation:

Registry Keys Affected by WOW64
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384253.aspx

When I look in my Win7 x64 computer's registry under HKCU/Software I
find the Wow6432Node node there but no entries except from Microsoft
below it.

That is a bug in some of Microsoft's apps, creating that key when they shouldn't
be (Embarcadero has a similar bug in its AutoRun\UpdateCheck key). The real
Wow6432 node does not apply to HKCU\Software at all, per the documentation
above.

Specifically my own 32 bit applications which write to
HKCU/Software/Company... etc seem to stuff the data into the
regular place where they also can retrieve them.

As they should be.

OTOH in HKLM I see a fair number of entries below Wow6432Node.

As they should be.

In the current case the config data go to HKLM but what I found with
the legacy app is that it reads from HKLM/Software/Wow6432Node/...

As it should be.

So if my Delphi 32 bit applications just write to the registry and do
not themselves go to the Wow6432Node I am hosed concerning the
config app, it must write the data to the Wow6432Node if it runs on
a 64 bit system but not if it runs on a 32 bit system...

This is where your logic is wrong. If the config app is also 32bit then
it will be redirected to the same keys that the legacy app is redirected
to. You don't have to deal with the Wow6432Node manually at all, the OS
will handle it for you. You only have to deal with Wow6432Node if if your
confiig app is 64bit, and even then you still don't need to deal with Wow6432Node
directly, let the OS handle it for you. You just need to add the KEY_WOW64_32KEY
flag when you want to access 32bit keys from a 64bit process.

--
Remy Lebeau (TeamB)
Anders Isaksson


Posts: 30
Registered: 4/15/00
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 7:47 AM   in response to: Bo Berglund in response to: Bo Berglund
Bo Berglund wrote:

located below HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...

You are aware that normal users don't generally have write access to
HKLM? You'd need admin rights to write there.

If the legacy program is written in Delphi a long time ago, it may also
have trouble reading HKLM, as the default access for a TRegistry
object was (is still?) full access, which you won't get as normal user.

Read more about it here:
http://stackoverflow.com/questions/1681434/registry-access-in-non-admin-mode
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 10:10 AM   in response to: Anders Isaksson in response to: Anders Isaksson
Anders Isaksson wrote:

Bo Berglund wrote:

located below HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...

You are aware that normal users don't generally have write access to
HKLM? You'd need admin rights to write there.

If the legacy program is written in Delphi a long time ago, it may
also have trouble reading HKLM, as the default access for a TRegistry
object was (is still?) full access, which you won't get as normal
user.

Read more about it here:
http://stackoverflow.com/questions/1681434/registry-access-in-non-admin-mode

Yes I am aware of this. It is about a server side service utility we
use a lot but its configuration applet for Control Panel won't show up
on recent Windows versions. Configuration is always an admin task so
that is no problem (run as administrator).
The utility is not written by us, I believe it is a Visual Studio 6
application. In any case it reads its data from HKLM when the service
starts.

Currently it runs on a Windows 2003 Server, but since it has passed
"End of Life" with Microsoft we need to move to a more recent server
version. The utility itself runs fine on recent platforms too, if one
manually configures it via RegEdit, but that is a PITA and therefore I
realized I had to try and make a new config utility using Delphi (which
is what I use for development).

And when I investigated the possibilities I also found this problem
with the Wow6432Node storage....

--

Bo Berglund
Sweden & Texas
now using XanaNews 1.20-0cfde51
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 23, 2016 2:15 PM   in response to: Bo Berglund in response to: Bo Berglund
Bo wrote:

After some extensive testing I found that the application actually
reads from (and presumably writes to) the same key as expected but
located below HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\...

As it should be. That is by design as part of the WOW64 emulation system:

Registry Redirector
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384232.aspx

Registry Keys Affected by WOW64
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384253.aspx

The redirection is performed silently at the OS layer, the app never knows
or cares that it is being redirected. This is completely normal behavior.

Is there something special I have to look out for concerning the
registry read/write in order to produce data readable by the old
legacy application?

If your config app is 32bit running on a 64bit system, it will get redirected
the same way the legacy app does. You don't have to do anything special
for that. It is when you want the config app to start doing things differently
that you then have to write different code to handle it.

Accessing an Alternate Registry View
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx

Do I specifically use the key above in my configurator or is there
some switch in the registry handling I need to activate?

If your config app is 32bit, you don't have to do anything special.

If your config app is 64bit, and you want to read/write to the 32bit redirected
key under Wow6432, you have to use the KEY_WOW64_32KEY flag when opening
the key.

Note that on a 32 bit platform I do not think that the Wow6432Node key
exists

No, it does not.

I need my configurator to be able to handle both 32 and 64 bit platforms
from the 32 bit Delphi XE5 program.

The legacy app is 32bit, so your best option is to make the config app be
32bit as well, then everything will "just work" as expected. It is when
you start mixing 32bit and 64bit code that you have to be more explicit about
your intentions in your code.

--
Remy Lebeau (TeamB)
Bo Berglund

Posts: 757
Registered: 10/23/02
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 24, 2016 12:57 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

The legacy app is 32bit, so your best option is to make the config
app be 32bit as well, then everything will "just work" as expected.
It is when you start mixing 32bit and 64bit code that you have to be
more explicit about your intentions in your code.

Thanks for the clarification!
So the HKCU hive is not differentiating between 32 and 64 bit but HKLM
does. I have started on the configurator using XE5 and a plain VCL 32
bit application target. I did verify that its reads come from the
Wow6432Node branchand I guess that the writes will happen the same way.

Follow-up Question:
Whilst debugging writing to HKLM, do I need to start Delphi ad an admin
or how can I open the key with write permissions?
I think that the application will ask to be elevated when executed alone

--

Bo Berglund
Sweden & Texas
now using XanaNews 1.20-0cfde51
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Registry read/write on Win32 vs Win64
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 24, 2016 12:00 PM   in response to: Bo Berglund in response to: Bo Berglund
Bo wrote:

So the HKCU hive is not differentiating between 32 and 64 bit but
HKLM does.

For the most part, yes. But do read the documentation, because there are
some keys in HKCU that are effected.

I have started on the configurator using XE5 and a plain VCL 32 bit
application target. I did verify that its reads come from the Wow6432Node
branchand I guess that the writes will happen the same way.

Yes.

Whilst debugging writing to HKLM, do I need to start Delphi ad an
admin or how can I open the key with write permissions?

Yes, you need to run the debugger elevated to gain write access to HKLM.
Also, if your app is manifested to run elevated, but the IDE is not running
elevated, it will fail to load the app in the debugger.

I think that the application will ask to be elevated when executed
alone

Only if you have manifested it to request elevation. Otherwise, it will
not elevate automatically, it will simply fail to access HKLM at runtime.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02