Accessing SOFTWARE\Microsoft and SOFTWARE\Wow6432Node\Microsoft

Started by hienpham, October 29, 2013, 12:32:17 PM

Previous topic - Next topic

hienpham

Hi all,
  In order to seearch for a presence of a software on a system, I used to use
============================
           Key=RegOpenkey(@RegMachine, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
               ; and scan all its subkeys
               For x=0 to 999
           a=RegQueryKey(Key, x)
============================

For a software that we don't know if it is 32- or 64-bit, do I need to do it in 2 steps to access
                   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
and then      HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
by assigning 32 then 64 to the values of the RegOpenFlags?
I read the RegOpenFlags Help several times and the WWW Tech support, but do not figure what is the correct way to do that. The example in the help is too simple.
I tried to use RegOpenFlags(0) to scan in one shot both registries (\SOFTWARE\Wow6432Node\Microsoft and \SOFTWARE\Microsoft) but failed.

Thanks so much for any help.


Deana


Code (winbatch) Select

;***************************************************************************
;**
;**      Query both 32-bit and 64-bit uninstall registry keys
;**
;**   2 simple rules to accessing the registry on 64-bit systems:
;**
;**    1. NEVER directly access keys stored under WOW6432node.
;**
;**    2. If you do want access something under WOW6432node, just
;**       set the registry view to 32-bit using RegOpenFlags(32)
;**       and specify the key/value without using 'WOW6432node'
;**       in the registry path. (use it 's regular 32-bit key/value.)
;**
;***************************************************************************

subkey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

;Access 32-bit registry keys
ulist_32 = ''
RegOpenFlags( 32 )
handle = RegOpenKey( @REGMACHINE,  subkey )
For x=0 To 999
   key = RegQueryKey(handle, x)
   If key == "" Then Break
   If ulist_32 == "" Then ulist_32 =  key
   Else ulist_32 = ulist_32 : @tab : key 
Next
RegCloseKey(handle)
AskItemList( "32-bit Uninstall keys", ulist_32, @tab, @unsorted, @single )

;Access 64-bit registry keys
ulist_64 = ''
RegOpenFlags( 64 )
handle = RegOpenKey( @REGMACHINE,  subkey )
For x=0 To 999
   key = RegQueryKey(handle, x)
   If key == "" Then Break
   If ulist_64 == "" Then ulist_64 =  key
   Else ulist_64 = ulist_64 : @tab : key 
Next
RegCloseKey(handle)
AskItemList( "64-bit Uninstall keys", ulist_64, @tab, @unsorted, @single )
Exit
Deana F.
Technical Support
Wilson WindowWare Inc.

hienpham

I'm sorry Deana, it's my mistake. I was crazy, between the RegOpenflags(0) and RegOpenkey(@RegMachine,..), I had another RegOpenflags(32). Remove this RegOpenflags(32), everything works correctly.
What the difference between compiling my WinBatch with 32- and 64-bit? Why did you ask me that question?
I always compile my script with 32-bit Winbatch compiler.
Most of the systems in my company are 63-bit, do you think that I better compile my script using 64-bit compiler?

As usual, thanks so much for your help, Deana.

Deana

Asked, about the bitness of the script because...By default 32-bit WinBatch's registry functions default to the 64-bit view on 64-bit systems and the 32-bit view on 32-bit systems. The view can be changed on a per-function basis using the function's 'view-flag' parameter or globally using the 'RegOpenFlags' function.

Advantage of running 64-bit, would mostly be for users who would like to run scripts on system that do not have the 32-bit subsystem installed (WinPE and Windows 2008 R2). Just to clarify, most installations of Windows 2008 R2 are capable of running 32-bit programs like WinBatch so it is usually not necessary to compile a special 64-bit version of a script just because you want to execute it on Windows 2008 R2. However, the installation of the 32-bit system (WOW64) is optional for the special server core version of Windows 2008 R2. So it is *possible* that you might need a 64-bit executable for certain installations of Windows 2008 R2 but this is usually not the case.

While hardly ever necessary, there are a couple small advantages to compiling a script as a 64-bit executable. The first is that you don't have to worry as much about file and registry redirection with a 64-bit exe. The second advantage is that you can get a detectable performance boost for some CPU intensive scripts. you can see a 20% to 30% reduction in execution time of CPU intensive scripts. This varies widely from script to script so we don't make a lot of noise about it.
Deana F.
Technical Support
Wilson WindowWare Inc.

Mat

Deana,

I am trying to "clone" a 32-bit Registry Entry (on a 64-bit machine) by using the RegQueryStr(), and I get the correct Value.  And I can successfully add the ".reg" file contents IN, but HOW do I then get to the 64-bit KEY to Edit it with the RegSetValue()?   The BIG Problem seems to be that the 32-bit Value is in the
"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI" area and the 64-bit Value is in the
"HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI" area.

Please HELP !!! :o

Mat

Deana,

I even tried the RegOpenFlags( 32 ) and then RegOpenFlags( 64 ), but even when I try to RegQueryStr() on the 64-bit SZ value I get a "1452 Error: REG Functions: Unable to open (or create) specified subkey".

Any ideas of what I need to do?

Mat

Deana,

When I use []s around the Keys I get a "1233" RegQueryValue: Function Failed" error.

Deana

Apparently ODBC stores driver information as follows:

QuoteOn a x64 bit system for a x64 bit drivers: HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers
On a x64 bit system for a x32 bit drivers: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers

Here is a code sample for accessing 32 and 64 bit ODBC driver information:
[edit]
Code (winbatch) Select

bit_subkey = 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers'
RegOpenFlags( 32 )
items32 = RegQueryItem( @REGMACHINE, bit_subkey)
AskItemList( "32-bit ODBC Drivers ", items32, @tab, @unsorted, @single )

RegOpenFlags( 64 )
items64 = RegQueryItem( @REGMACHINE, bit_subkey, 64)
AskItemList( "64-bit ODBC Drivers ", items64, @tab, @unsorted, @single )

RegOpenFlags( 0 )


Deana F.
Technical Support
Wilson WindowWare Inc.

td

Never a reason to use 'Wow6432Node'.  The result of using it vary for OS versions so to write OS version independent scripts do the following:
Code (winbatch) Select

bit_subkey = 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers' 
items32 = RegQueryItem( @REGMACHINE, bit_subkey, 32)
AskItemList( "32-bit ODBC Drivers ", items32, @tab, @unsorted, @single )

items64 = RegQueryItem( @REGMACHINE, bit_subkey, 64)
AskItemList( "64-bit ODBC Drivers ", items64, @tab, @unsorted, @single )
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade