private void getxx(){
RegistryKey start = Registry.LocalMachine; 
RegistryKey cardServiceName, networkKey; 
string networkcardKey ="SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards"; 
string serviceKey = "SYSTEM\\CurrentControlSet\\Services\\"; 
string networkcardKeyName, deviceName; 
string deviceServiceName, serviceName; 
RegistryKey serviceNames = start.OpenSubKey(networkcardKey); 
 if (serviceNames == null) 
{ 
MessageBox.Show("Bad registry key"); 
return; 
} 
string[] networkCards = serviceNames.GetSubKeyNames(); 
serviceNames.Close(); 
foreach(string keyName in networkCards) 
{ 
networkcardKeyName = networkcardKey + "\\" + keyName; 
cardServiceName = start.OpenSubKey(networkcardKeyName); 
if (cardServiceName == null) 
{ 
    MessageBox.Show(networkcardKeyName);
return; 
} 
deviceServiceName =(string)cardServiceName.GetValue("ServiceName"); 
deviceName = (string)cardServiceName.GetValue("Description"); 
    MessageBox.Show( deviceName);
serviceName = serviceKey + deviceServiceName + "\\Parameters\\Tcpip"; 
networkKey = start.OpenSubKey(serviceName); 
if (networkKey == null) 
{ 

。。。。。。
} 
else 
{ 
string[] ipaddresses =(string[])networkKey.GetValue("IPAddress"); 
string[] defaultGateways =(string[])networkKey.GetValue("DefaultGateway"); 
string[] subnetmasks =(string[])networkKey.GetValue("SubnetMask"); 
foreach(string ipaddress in ipaddresses) 
{ 
    MessageBox.Show( ipaddress);
     } 
foreach(string subnetmask in subnetmasks) 
{  
。。。。。。} 
foreach(string defaultGateway in defaultGateways) 
{ 
    MessageBox.Show(defaultGateway);
} 
networkKey.Close(); 
} 
} 
start.Close(); 
        }

posted on 2010-08-30 12:11  wenbing  阅读(437)  评论(0编辑  收藏  举报