0

im trying to get all programs installed from a remote computer. Im using the code bellow:

private void button1_Click_1(object sender, EventArgs e)
        {
           foreach (string registro in registry_keys)
            {
                Console.WriteLine("#################################");

                RegistryKey key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "XXXXXX").OpenSubKey(registro);

                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        Console.WriteLine(subkey.GetValue("DisplayName"));
                    }
                }

            }

        }

But in each loop from the foreach loop, it returns the exact same programs. Also, some programs that do have a displayname, such as Microsoft Azure Compute Emulator - v2.9.5.3, seems to be returning a blank line.

I'm new to c# and been trying to figure this out for hours with no success.

mergulhao21
  • 33
  • 1
  • 7
  • I never did it on a remote machine but i've done it on local..Do you want an answer regarding that ? – Software Dev Apr 19 '18 at 19:46
  • I'd appreciate that! – mergulhao21 Apr 19 '18 at 20:06
  • Take a look at [this](https://stackoverflow.com/questions/24909108/get-installed-software-list-using-c-sharp) – Software Dev Apr 19 '18 at 20:19
  • I have managed to do it like this. RegistryKey Key32 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, equipamento, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); RegistryKey Key32 = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, equipamento, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); That way it will get the results from both 32 and 64 bit installed programs. – mergulhao21 Apr 26 '18 at 13:28

1 Answers1

0

If I'm not mistaken, the "OpenRemoteBaseKey" returns all the applications that the current user can see on the target machine. This means that if an application installed for a different user (other than the current user that currently logged into the system), it won't show up with this code. Try the following and see if you can see all the applications you are looking for.

string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
    foreach(string subkey_name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(subkey_name))
        {
            Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}
Saeid
  • 1,573
  • 3
  • 19
  • 37