任何人都知道,如何以编程方式获取0001,0002或0005等子键? 从
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}
在这些键0001,0002 ...气体存储有关NIC卡的信息!
答案 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