Registry access doesnt work on x86 vista build

S

ShaunO

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.

Thanks,
Shaun


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()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
GetInstalledApps();
}

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();
listBox1.Items.Add(name);

}
}
}
}
}
 
A

Alberto Poblacion

ShaunO said:
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.

You are probablu running under Vista 64bits. When you compile for "Any
CPU" your program runs as a 64-bit executable, but when you compile it for
"x86" it runs as a 32-bit executable.
Now, there is a difference in Registry access in Vista for 32-bit and
64-bit executables. Registry Virtualization is disabled for 64 bits, but it
is enabled for 32 bits. This means that registry accesses to
(HKEY_LOCAL_MACHINE\Software) are redirected to a per-user location within
the user's profile known as the virtual store (HKEY_USERS\<User
SID>_Classes\VirtualStore\Machine\Software). This is why your program is
exhibiting the behaviour that you are seeing.

I believe that you can disable Registry Virtualization for specific Keys
by means of the REG.EXE command, but I have never tried it out.
 
S

ShaunO

Thanks Alberto

Could you please advise how best to proceed. Would running with admin
priveledges do the job ?
I cant build my app as 64bit because it uses an old mappoint activeX and a
3rd party .dll that only work under 32.
What do you recommend ?

Thanks,
Shaun
 
A

Alberto Poblacion

ShaunO said:
Could you please advise how best to proceed. Would running with admin
priveledges do the job ?
I cant build my app as 64bit because it uses an old mappoint activeX and a
3rd party .dll that only work under 32.
What do you recommend ?

Well, the documentation at
http://msdn.microsoft.com/en-us/library/aa965884(VS.85).aspx lists various
cases in which registry virtualization is disabled. You can examine them to
see if you can modify your program to make use of one of those alternatives
(such as impersonating a different user, or running as a service, or having
a requestedExecutionLevel in the manifest).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top