如何获取特定的注册表项子项

时间:2012-07-30 11:45:17

标签: c# registry nic

任何人都知道,如何以编程方式获取0001,0002或0005等子键? 从

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}

在这些键0001,0002 ...气体存储有关NIC卡的信息!

2 个答案:

答案 0 :(得分:2)

使用Microsoft.Win32.Registry / .RegistryKey类 例如:

using Microsoft.Win32;
...
//Where CardInformation is some data structure to hold the information.

public static IEnumerable<CardInformation> GetCardInformation()
{
    string cardsKeyAddress =  "\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}";
    RegistryKey cardsKey = Registry.LocalMachine.OpenSubKey(cardsKeyAddress);
    string[] cardNumbers = cardsKey.GetSubKeyNames();

    foreach(string n in cardNumbers)
        yield return LoadCardInformation(cardsKeyAddress+"\\"+n);
}
static CardInformation LoadCardInformation(string key)
{
    //Get whatever values from the key to return
    CardInfomation info = new CardInformation();
    info.Name = Registry.GetValue(key, "Name", "Unnamed");
    return info;
}

答案 1 :(得分:1)

您可以使用Microsoft.Win32.Registry和相同的类来执行此操作。阅读更多here

相关问题