0

Im using Management class that i don't really know about, just to read remote registry :

        string regKeyToGet = @"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources";
        string keyToRead = "Description";
        ConnectionOptions oConn = new ConnectionOptions();
        oConn.Username = "user1";
        oConn.Password = "user1password";

        ManagementScope scope = new ManagementScope(@"//" + "PC1" + @"/root/default", oConn);
        ManagementClass registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);

        ManagementBaseObject inParams = registry.GetMethodParameters("GetStringValue");
        inParams["sSubKeyName"] = regKeyToGet;
        inParams["sValueName"] = keyToRead;
        ManagementBaseObject outParams = registry.InvokeMethod("GetStringValue", inParams, null);
        MessageBox.Show(outParams["sValue"].ToString());

This code returns me a specific value for a specified key but what i need is to return an array of name value just like :

RegistryKey regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, PC1, RegistryView.Registry64).OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources");
regKey.GetValueNames();
pharaon450
  • 493
  • 3
  • 9
  • 21

1 Answers1

0

After some research i found the way to do it, here is the code :

        ConnectionOptions oConn = new ConnectionOptions();
        oConn.Username = "user1";
        oConn.Password = "user1password";
        ManagementScope scope = new ManagementScope(@"//" + "PC1" + @"/root/default", oConn);
        scope.Connect();

        ManagementClass mc = new ManagementClass("stdRegProv");
        mc.Scope = scope;

        ManagementBaseObject mbo;
        mbo = mc.GetMethodParameters("EnumValues");

        mbo.SetPropertyValue("sSubKeyName", @"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources");

        string[] subkeys = (string[])mc.InvokeMethod("EnumValues", mbo, null).Properties["sNames"].Value;

        foreach (string strKey in subkeys)
        {
            MessageBox.Show(strKey);
        } 

I found help at the page : How to Read Remote Registry Keys?

Community
  • 1
  • 1
pharaon450
  • 493
  • 3
  • 9
  • 21