我使用我不太了解的管理类,只是为了读取远程注册表:
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());
此代码为我返回指定键的特定值,但我需要返回一个名称值数组,如下所示:
RegistryKey regKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.CurrentUser, PC1, RegistryView.Registry64).OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources");
regKey.GetValueNames();