Search code examples
c#adobex86versionanycpu

Platform target x86 and Any CPU


I have small problem with simple code. This code is working properly on "x86" mode but not on "Any CPU" mode, maybe it is possible to run one class on "x86" and another class on "Any CPU" mode? Code:

namespace Software_Info_v1._0
{
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

public class Adobe
{
    public string GetAdobeVersion()
    {
        try
        {
            RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe");
            if (adobe != null)
            {
                RegistryKey acroRead = adobe.OpenSubKey("Acrobat Reader");
                if (acroRead != null)
                {
                    string[] acroReadVersions = acroRead.GetSubKeyNames();
                    foreach (string versionNumber in acroReadVersions)
                    {
                        Console.WriteLine("Acrobat Reader version: " + versionNumber);
                    }
                }
            }
        }
        catch
        {
        }
        return null;
    }
}
}

Solution

  • This is because of registry redirection.

    The structure of the registry is different for 32-bit and 64-bit OS.

    Assuming you are running your application on a 64-bit machine, compiling for x86 target makes your program run using WOW64 mode (32-bit process on 64-bit) and you're reading keys under the Wow6432Node. See Weird behaviour when reading registry in C#