C# : specific installed software on a remote computer could not be found

  .net, c++, registry, windows

I have this code shown below to read installed software on a specific device from the registry:

private static List<string> ReadRemoteRegistryusingWMI(string machineName= "192.168.x.x")
        List<string> programs = new List<string>();

        ConnectionOptions connectionOptions = new ConnectionOptions();
        connectionOptions.Username = @"****";
        connectionOptions.Password = @"****";
        //connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
        ManagementScope scope = new ManagementScope("\" + machineName + "rootCIMV2", connectionOptions);

        string softwareRegLoc = @"SoftwareMicrosoftWindowsCurrentVersionUninstall";

        ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
        ManagementBaseObject inParams = registry.GetMethodParameters("EnumKey");
        inParams["hDefKey"] = 0x80000002;//HKEY_LOCAL_MACHINE
        inParams["sSubKeyName"] = softwareRegLoc;

        // Read Registry Key Names 
        ManagementBaseObject outParams = registry.InvokeMethod("EnumKey", inParams, null);
        string[] programGuids = outParams["sNames"] as string[];

        foreach (string subKeyName in programGuids)
            inParams = registry.GetMethodParameters("GetStringValue");
            inParams["hDefKey"] = 0x80000002;//HKEY_LOCAL_MACHINE
            inParams["sSubKeyName"] = softwareRegLoc + @"" + subKeyName;
            inParams["sValueName"] = "DisplayName";
            // Read Registry Value 
            outParams = registry.InvokeMethod("GetStringValue", inParams, null);

            if (outParams.Properties["sValue"].Value != null)
                string softwareName = outParams.Properties["sValue"].Value.ToString();
        programs = programs.OrderBy(x => x).ToList();
        return programs;

But the read list is not complete and despite existence of some software in the registry root it doesn’t appear in the list.

Here is a screenshot of a specific software package that exists in the registry root @"SoftwareMicrosoftWindowsCurrentVersionUninstall" but is not loaded with my code into the list:

enter image description here

Source: Windows Questions

One Reply to “C# : specific installed software on a remote computer could not be found”

  • Sample does not work. your “ManagementScope scope = new ManagementScope(“\” + machineName + “rootCIMV2″, connectionOptions);” line syntax error.

    New syntax: ManagementScope scope = new ManagementScope(@”\\” + machineName [email protected] “\rootCIMV2”, connectionOptions);

    Your “connectOptions” looks like
    connectionOptions.Username = “Administrator”;
    connectionOptions.Password = “AdminPassword”;
    connectionOptions.Impersonation = ImpersonationLevel.Impersonate;