(FYI)Accessing WinXP-64bit registry items

There probably aren’t a lot of WinXP-64bit users out there yet, but I
post this for future reference:

I was using the win32/registry (as in ‘require “win32/registry”’)
package to access the registry to figure out if certiain apps were
installed on a Windows box. The script worked fine on my Win2K box,
but when someone tried it on their WinXP-64bit edition box it didn’t
find the installed apps as it should have.

Turns out that in 64bit windows there are two sections to the
registry, a 32bit section and a 64bit section. I couldn’t see the
64bit apps from the Ruby script (using the standard Ruby install
created by Andy Hunt, so it’s 32 bits). After some research, I found
out that you’ve got to add some new registry access rights.

The solution is that you need to add some new access rights keys in
your Win32::Registry::Constants module:

  KEY_WOW64_64KEY = 0x0100
  KEY_WOW64_32KEY = 0x0200

And then OR them into KEY_READ:

  KEY_READ = STANDARD_RIGHTS_READ | KEY_WOW64_64KEY |

KEY_WOW64_32KEY |
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY

After I did that it worked fine – I was able to see the 64bit registry
entries.

How’s that for obscure? :wink:

You can find more info here:

http://msdn.microsoft.com/library/default.asp?url=/library/enus/sysinfo/base/registry_key_security_and_access_rights.asp

I’ve notified Usa Nakamura who I’m told is the registry.rb maintainer,
so hopefully, by the time you need this in the 64bit future it will
work OK out of the box.

Phil

In article c68ca8f2.0312291659.7c864268@posting.google.com,

There probably aren’t a lot of WinXP-64bit users out there yet, but I
post this for future reference:

I was using the win32/registry (as in ‘require “win32/registry”’)
package to access the registry to figure out if certiain apps were
installed on a Windows box. The script worked fine on my Win2K box,
but when someone tried it on their WinXP-64bit edition box it didn’t
find the installed apps as it should have.

Turns out that in 64bit windows there are two sections to the
registry, a 32bit section and a 64bit section. I couldn’t see the
64bit apps from the Ruby script (using the standard Ruby install
created by Andy Hunt, so it’s 32 bits). After some research, I found
out that you’ve got to add some new registry access rights.

The solution is that you need to add some new access rights keys in
your Win32::Registry::Constants module:

 KEY_WOW64_64KEY = 0x0100
 KEY_WOW64_32KEY = 0x0200

And then OR them into KEY_READ:

 KEY_READ = STANDARD_RIGHTS_READ | KEY_WOW64_64KEY |

KEY_WOW64_32KEY |
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY

After I did that it worked fine – I was able to see the 64bit registry
entries.

How’s that for obscure? :wink:

You can find more info here:

Technical documentation | Microsoft Learn

I’ve notified Usa Nakamura who I’m told is the registry.rb maintainer,
so hopefully, by the time you need this in the 64bit future it will
work OK out of the box.

Well, I spoke a bit too soon… Sure it works on 64-bit Windows, but it
breaks now on 32-bit Windows.

Looks like we need to come up with some reliable way to determine if
you’re running on 64bit WinXP or 32Bit WinXP and then do something like:

KEY_READ |= (KEY_WOW64_64KEY | KEY_WOW64_32KEY) if XP64

Any ideas for how to determine XP64?

Phil

···

Phil Tomson intc_ctor@yahoo.com wrote:

ptkwt@aracnet.com (Phil Tomson) wrote in message news:bsqqb502b3k@enews4.newsguy.com

In article c68ca8f2.0312291659.7c864268@posting.google.com,

There probably aren’t a lot of WinXP-64bit users out there yet, but I
post this for future reference:

I was using the win32/registry (as in ‘require “win32/registry”’)
package to access the registry to figure out if certiain apps were
installed on a Windows box. The script worked fine on my Win2K box,
but when someone tried it on their WinXP-64bit edition box it didn’t
find the installed apps as it should have.

Turns out that in 64bit windows there are two sections to the
registry, a 32bit section and a 64bit section. I couldn’t see the
64bit apps from the Ruby script (using the standard Ruby install
created by Andy Hunt, so it’s 32 bits). After some research, I found
out that you’ve got to add some new registry access rights.

The solution is that you need to add some new access rights keys in
your Win32::Registry::Constants module:

 KEY_WOW64_64KEY = 0x0100
 KEY_WOW64_32KEY = 0x0200

And then OR them into KEY_READ:

 KEY_READ = STANDARD_RIGHTS_READ | KEY_WOW64_64KEY |

KEY_WOW64_32KEY |
KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY

After I did that it worked fine ? I was able to see the 64bit registry
entries.

How’s that for obscure? :wink:

You can find more info here:

Technical documentation | Microsoft Learn

I’ve notified Usa Nakamura who I’m told is the registry.rb maintainer,
so hopefully, by the time you need this in the 64bit future it will
work OK out of the box.

Well, I spoke a bit too soon… Sure it works on 64-bit Windows, but it
breaks now on 32-bit Windows.

Looks like we need to come up with some reliable way to determine if
you’re running on 64bit WinXP or 32Bit WinXP and then do something like:

KEY_READ |= (KEY_WOW64_64KEY | KEY_WOW64_32KEY) if XP64

Any ideas for how to determine XP64?

Here’s what I had to do to determine if the script is running on
WinXP64 (changes to win32/registry.rb):

require ‘Win32API’
module Win32
class Registry
module Constants
#since IsWow64Process only exists on XP we need to do
#a rescue in case we’re not running on an XP machine:
begin
IsWow64Process=Win32API.new(“kernel32”,“IsWow64Process”,[‘L’,‘P’],‘L’)
rescue
puts “you’re not on XP” if $DEBUG
isXP = false
else
puts “you’re on XP: could be 32 or 64 bit” if $DEBUG
isXP = true
end

  GetCurrentProcess =

Win32API.new(“kernel32”,“GetCurrentProcess”,,‘L’)

#

  KEY_WOW64_64KEY = 0x0100
  KEY_WOW64_32KEY = 0x0200
  key_read = STANDARD_RIGHTS_READ | 
    KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY
  if isXP
    is64 = ""
result = IsWow64Process.call(GetCurrentProcess.call(),is64)
is64 = true if is64.unpack("c")[0].to_i != 0
if is64
      puts "This script is running on WinXP 64bit edition" if

$DEBUG
key_read |= (KEY_WOW64_64KEY | KEY_WOW64_32KEY )
end
end
KEY_READ = key_read

#

end

end
end

···

Phil Tomson intc_ctor@yahoo.com wrote:
########

Now this works on WinXP or NOT(WinXP) Windows boxen.

Phil