简体   繁体   English

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

[英]How to get specific registry key subkey

Anybody knows, how can get programmatically get subkey like 0001 , 0002 , or 0005 and so on ? 有谁知道,如何以编程方式获得像0001,0002或0005等子键? From

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

In these keys 0001 , 0002 ... gas stored information about NIC cards ! 在这些键0001,0002 ...气体存储有关NIC卡的信息!

Use the Microsoft.Win32.Registry / .RegistryKey classes. 使用Microsoft.Win32.Registry / .RegistryKey类。
Example: 例:

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;
}

you can use Microsoft.Win32.Registry and the same classes to do that. 你可以使用Microsoft.Win32.Registry和相同的类来做到这一点。 Read more here 在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM