Working With 32-bit and 64-bit Registry

Applies to TestComplete 15.47, last modified on January 20, 2023
Information in this topic applies to desktop applications only.

Task Description

Computers running 64-bit operating systems store information on 32-bit and 64-bit applications separately. Registry information on 32-bit applications running in WOW64 (Windows on Windows 64) mode is stored in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node registry branch.

If your test is run on a 64-bit operating system, all registry calls made from within your tests to registry keys and values are redirected to the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node branch.

If your test works with the system registry, make sure that it works with the appropriate registry branch.

Possible Solution

To access the Windows operating system’s registry from tests, use the Storages.Registry method. It lets you specify whether you want to use a 32-bit or 64-bit registry.

The following code demonstrates how to use Storages.Registry method to obtain registry values:

JavaScript, JScript

// Enumerates installed applications and posts information on them to the test log
function EnumerateApps(OSType)

{
  var Key, KeyName, ValueName, Count, DisplayName, InstallSource, UninstallString, Data, i;

  if (OSType == 0 || OSType == 1)
  {
    Log.AppendFolder("Installed " + (OSType == 0 ? "32" : "64") + "-bit applications:");

    // Gets an object for the system registry key
    KeyName = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
    Key = Storages.Registry(KeyName, HKEY_LOCAL_MACHINE, OSType);

    // Determines how many keys the current key contains
    Count = Key.SectionCount;

    // Iterates through keys
    for (i = 0; i < Count; i++)
    {
      // Obtains the key by its index
      var s = Key.GetSubSectionByIndex(i);

      // Obtains key values
      DisplayName = s.GetOption("DisplayName", "not specified");

      if (DisplayName != "not specified")
      {
        InstallSource = s.GetOption("InstallSource", "not specified");
        UninstallString = s.GetOption("UninstallString", "not specified");
        Data = "InstallSource: " + InstallSource + "\r\n" + "UninstallString: " + UninstallString;

        // Posts key values to the test log
        Log.Message(DisplayName, Data);
      }
    }

    Log.PopLogFolder();

  }

}

function Test()
{
  // Determines the OS version and calls the function that enumerates installed applications
  if (Sys.OSInfo.Windows64bit)
  {
    EnumerateApps(0);
    EnumerateApps(1);
  }
  else
  {
    EnumerateApps(0);
  }
}

Python

# Enumerates installed applications and posts information on them to the test log
def EnumerateApps(OSType):

  if OSType == 0 or OSType == 1:
    if OSType == 1:
      OSBit = '64'
    else:
      OSBit = '32'
    
    Log.AppendFolder('Installed ' + OSBit + '-bit applications:')

    # Gets an object for the system registry key
    KeyName = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
    Key = Storages.Registry(KeyName, HKEY_LOCAL_MACHINE, OSType)

    # Determines how many keys the current key contains
    Count = Key.SectionCount;

    # Iterates through keys
    for i in range(0, Count):
      # Obtains the key by its index
      s = Key.GetSubSectionByIndex(i)

      # Obtains key values
      DisplayName = s.GetOption("DisplayName", "not specified")

      if DisplayName != "not specified":
        InstallSource = s.GetOption("InstallSource", "not specified")
        UninstallString = s.GetOption("UninstallString", "not specified")
        Data = "InstallSource: " + InstallSource + "\r\n" + "UninstallString: " + UninstallString

        # Posts key values to the test log
        Log.Message(DisplayName, Data)

    Log.PopLogFolder()

    
def Test():
  # Determines the OS version and calls the function that enumerates installed applications
  if Sys.OSInfo.Windows64bit:
    EnumerateApps(0)
    EnumerateApps(1)
  else:
    EnumerateApps(0)

VBScript

Sub Test
  ' Determines the OS version and calls the function that enumerates installed applications
  If Sys.OSInfo.Windows64bit Then
    EnumerateApps(0)
    EnumerateApps(1)
  Else
    EnumerateApps(0)
  End If
End Sub

' Enumerates installed applications and posts information on them to the test log
Sub EnumerateApps(OSType)

  Dim OSBit, Key, KeyName, ValueName, Count, DisplayName, InstallSource, UninstallString, Data, i

  If OSType = 0 Or OSType = 1 Then

    If OSType = 1 Then
      OSBit = "64"
    Else
      OSBit = "32"
    End If

    Log.AppendFolder("Installed " & OSBit & "-bit applications:")

    ' Gets an object for the system registry key
    KeyName = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
    Set Key = Storages.Registry(KeyName, HKEY_LOCAL_MACHINE, OSType)

    ' Determines how many keys the current key contains
    Count = Key.SectionCount

    ' Iterates through keys
    For i = 0 To Count - 1
      ' Obtains the key by its index
      Set s = Key.GetSubSectionByIndex(i)

      ' Obtains key values
      DisplayName = s.GetOption("DisplayName", "not specified")

      If Not DisplayName = "not specified" Then
        InstallSource = s.GetOption("InstallSource", "not specified")
        UninstallString = s.GetOption("UninstallString", "not specified")
        Data = "InstallSource: " & InstallSource & vbCrLf & "UninstallString: " & UninstallString

        ' Posts key values to the test log
        Call Log.Message(DisplayName, Data)
      End If
    Next
    Log.PopLogFolder
  End If

End Sub

DelphiScript

// Enumerates installed applications and posts information on them to the test log
procedure EnumerateApps(OSType);
var OSBit, Key, KeyName, ValueName, Count, DisplayName, InstallSource, UninstallString, Data, i, s;
begin
  if ((OSType = 0) or (OSType = 1)) then

    begin
      if OSType = 1 then
        OSBit := '64'
      else
        OSBit := '32';

      Log.AppendFolder('Installed ' + OSBit + '-bit applications:');

      // Gets an object for the system registry key
      KeyName := 'Software\Microsoft\Windows\CurrentVersion\Uninstall';
      Key := Storages.Registry(KeyName, HKEY_LOCAL_MACHINE, OSType);

      // Determines how many keys the current key contains
      Count := Key.SectionCount;

      // Iterates through keys
      for i := 0 to Count - 1 do
        begin
          // Obtains the key by its index
          s := Key.GetSubSectionByIndex(i);

          // Obtains key values
          DisplayName := s.GetOption('DisplayName', 'not specified');

          if DisplayName <> 'not specified' then
            begin
              InstallSource := s.GetOption('InstallSource', 'not specified');
              UninstallString := s.GetOption('UninstallString', 'not specified');
              Data := 'InstallSource: ' + InstallSource + #13#10 + 'UninstallString: ' + UninstallString;

              // Posts key values to the test log
              Log.Message(DisplayName, Data);
            end;
        end;
      Log.PopLogFolder;
    end;

end;

procedure Test();
begin
  // Determines the OS version and calls the function that enumerates installed applications
  if Sys.OSInfo.Windows64bit then
    begin
      EnumerateApps(0);
      EnumerateApps(1);
    end
  else
    EnumerateApps(0);
end;

C++Script, C#Script

// Enumerates installed applications and posts information on them to the test log
function EnumerateApps(OSType)

{
  var Key, KeyName, ValueName, Count, DisplayName, InstallSource, UninstallString, Data, i;

  if (OSType == 0 || OSType == 1)
  {
    Log["AppendFolder"]("Installed " + (OSType == 0 ? "32" : "64") + "-bit applications:");

    // Gets an object for the system registry key
    KeyName = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
    Key = Storages["Registry"](KeyName, HKEY_LOCAL_MACHINE, OSType);

    // Determines how many keys the current key contains
    Count = Key["SectionCount"];

    // Iterates through keys
    for (i = 0; i < Count; i++)
    {
      // Obtains the key by its index
      var s = Key["GetSubSectionByIndex"](i);

      // Obtains key values
      DisplayName = s["GetOption"]("DisplayName", "not specified");

      if (DisplayName != "not specified")
      {
        InstallSource = s["GetOption"]("InstallSource", "not specified");
        UninstallString = s["GetOption"]("UninstallString", "not specified");
        Data = "InstallSource: " + InstallSource + "\r\n" + "UninstallString: " + UninstallString;

        // Posts key values to the test log
        Log["Message"](DisplayName, Data);
      }
    }

    Log["PopLogFolder"]();

  }

}

function Test()
{
  // Determines the OS version and calls the function that enumerates installed applications
  if (Sys["OSInfo"]["Windows64bit"])
  {
    EnumerateApps(0);
    EnumerateApps(1);
  }
  else
  {
    EnumerateApps(0);
  }
}

See Also

Registry Method
Reading Sections and Options from the System Registry. Example

Highlight search results