void MineRegistryForPortName(string strStartKey, Hashtable oTargetMap, string[] oPortNamesToMatch)
{
if (oTargetMap.Count >= oPortNamesToMatch.Length)
return;
RegistryKey oCurrentKey = Registry.LocalMachine;
try
{
oCurrentKey = oCurrentKey.OpenSubKey(strStartKey);
string[] oSubKeyNames = oCurrentKey.GetSubKeyNames();
if (((IList<string>)oSubKeyNames).Contains("Device Parameters") && strStartKey != "SYSTEM\\CurrentControlSet\\Enum")
{
object oPortNameValue = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + strStartKey + "\\Device Parameters", "PortName", null);
if (oPortNameValue == null || ((IList<string>)oPortNamesToMatch).Contains(oPortNameValue.ToString()) == false)
return;
object oFriendlyName = Registry.GetValue("HKEY_LOCAL_MACHINE\\" + strStartKey, "FriendlyName", null);
string strFriendlyName = "N/A";
if (oFriendlyName != null)
strFriendlyName = oFriendlyName.ToString();
if (strFriendlyName.Contains(oPortNameValue.ToString()) == false)
strFriendlyName = string.Format("{0} ({1})", strFriendlyName, oPortNameValue);
oTargetMap[strFriendlyName] = oPortNameValue;
}
else
{
foreach (string strSubKey in oSubKeyNames)
MineRegistryForPortName(strStartKey + "\\" + strSubKey, oTargetMap, oPortNamesToMatch);
}
}
catch
{
}
}