Vista Registry access doesnt work on x86 build

Note: VS2005, Vista 64

Hi, when i run the following code, it only works if i build it for "Any CPU" if i choose "x86" then the listbox is empty rather than full of application names read from the registry
Could someone please advise how to achieve this result with code that works under x86 build


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WindowsApplication17
    public partial class Form1 : Form
        public Form1()
        private void Form1_Load(object sender, EventArgs e)
        public void GetInstalledApps()
            //string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            string software = "";
            string softwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products";
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(softwareKey, false))
                foreach (string skName in rk.GetSubKeyNames())
                    string name = Registry.LocalMachine.OpenSubKey(softwareKey, false).OpenSubKey(skName, false).OpenSubKey("InstallProperties", false).GetValue("DisplayName").ToString();

Open in new window

Who is Participating?
grayeConnect With a Mentor Commented:
What you're seeing is related to "Registry Virtualization" in Vista x64.
Unfortunately, the native Registry classes in the .Net Framework do not allow to "pick" a virtualized view of the registry.   So, when run as a 32-bit app, it only sees the 32-bit virtualized registry... likewise, when run as a 64-bit app, it only sees the 64-bit registry.
I've started a project that overcomes this limation on CodePlex...  it currently works for ReadOnly acccess, but could be easily expanded to add write capabilities.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.