Other Languages - how to get the names of the Connections??

Asked By akshay on 12-Oct-11 07:20 AM
how can I get a local area connection name (the string, exactly as I see it 
in Network Connections)? I looked in iphelper functions, but I can only 
obtain the adaptor name, but not the connection name itself.
I need this name to be able to pass it to netsh.exe program to setup IP 
adress, subnet mask ant gateway address programmatically
(so I call "netsh.exe interface ip set address "Connection name" static IP 
SUBNET GATEWAY 1").... Need the solutin in Visual C++(MFC)..


Thanks in advance
Akshay...
Sri K replied to akshay on 12-Oct-11 07:27 AM
That's what I get for not reading the question close enough. :-/ 

See if this works out better for you:

ManagementScope oMs = new ManagementScope();  
ObjectQuery oQuery =  
  new ObjectQuery("Select * From Win32_NetworkAdapter");  
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery);  
ManagementObjectCollection oReturnCollection = oSearcher.Get();  
foreach (ManagementObject oReturn in oReturnCollection)  
  if (oReturn.Properties["NetConnectionID"].Value != null)  
    Console.WriteLine("Name : " + oReturn.Properties["NetConnectionID"].Value); 

On my machine that returns:

Name : Local Area Connection
Name : Wireless Network Connection

Sound more like what you're after?
smr replied to akshay on 12-Oct-11 07:35 AM
HI

this should work

System.Management.ManagementScope oMs = new System.Management.ManagementScope(); 
System.Management.ObjectQuery oQuery =  
  new System.Management.ObjectQuery("Select * From Win32_NetworkAdapterConfiguration"); 
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(oMs, oQuery); 
ManagementObjectCollection oReturnCollection = oSearcher.Get(); 
foreach (ManagementObject oReturn in oReturnCollection) 
  Console.WriteLine("Name : " + oReturn["Description"].ToString());

Make sure you add a reference to System.Management