Hi all ! I have a code which search registry key value in specific key path, not all registry.
In registry key SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
find all keys with 0000 , 0001 , 0002 , 0003
and so on at the end of registry key. {4D36E972-E325-11CE-BFC1-08002BE10318}
. In each key ( for example 0007
) are subkey called NetCfgInstanceId
which holds network interface
card ID value , like this {C80949A4-CEDA-4F29-BFE2-059856D7F745}
. If finds value, method returns key path ! Problem is an error Cannot convert type 'char' to 'string
inforeach (string key_value in key.GetValue("NetCfgInstanceId").ToString())
.
Full code is
public string key_path(RegistryKey root, string root_path, string search_key)
{
string path = string.Empty;
foreach (string keyname in root.GetSubKeyNames())
{
try
{
using (RegistryKey key = root.OpenSubKey(keyname, true))
{
foreach (string key_value in key.GetValue("NetCfgInstanceId").ToString())
{
if (key_value == search_key)
{
string reg_path = (string)key.GetValue("NetCfgInstanceId");
path = reg_path;
}
else
{
path = "Can't find key !";
}
}
}
}
catch (System.Security.SecurityException)
{
//Do nothing !!!
}
}
return path;
}
private void kryptonButton4_Click(object sender, EventArgs e)
{
var answer = key_path(Registry.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}", "{C80949A4-CEDA-4F29-BFE2-059856D7F745}");
MessageBox.Show(answer);
}
How can solve this problem ?
Cheers and thank's for advance !