2012-07-30 75 views
1

任何人都知道,如何以編程方式獲得像0001,0002或0005等子項? 從如何獲取特定的註冊表項子項

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

在這些鍵0001,0002 ......約網卡氣體存儲的信息!

回答

1

你可以使用Microsoft.Win32.Registry和相同的類來做到這一點。閱讀更多here

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