Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Network Connections
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Network Connections
Divers
Thread ID:
00996320
Message ID:
00996320
Vues:
53
Hi,

I have the following code:
try
{
	System.String sQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'";
	System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(sQuery);
	foreach (System.Management.ManagementObject nic in searcher.Get())
	{
		MessageBox.Show(nic["Description"].ToString() + "\n" + 
                                      ((System.String[]) nic["IPAddress"])[0] + "\n" + 
                                      ((System.String[]) nic["IPSubnet"])[0] + "\n" + 
                                      nic["Caption"].ToString() + "\n" + 
                                      nic["ServiceName"].ToString());
	}
}
catch(Exception Ex)
{
	MessageBox.Show(Ex.ToString());
}
This gives me information about the network connections on my computer. Now I got this crazy request to display the name of the network connection, from the name column in the Network Connections in the Control Panel. This name column can be renamed and my users would like to see the name that they gave to the network connection instead of the device name.

Any hints would be helpful.

UPDATE:
I have the solution but I am having some problems with it. If someone could test and review the code below:
				//System.String sQuery = "SELECT * FROM Win32_NetworkAdapter WHERE Availability = 3 AND MACAddress <> 'null' AND AdapterTypeID = 0";
				System.String sQuery = "SELECT * FROM Win32_NetworkAdapter";
				System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(sQuery);
				foreach (System.Management.ManagementObject nic in searcher.Get())
				{

					if (nic["NetConnectionID"] == null)
					{
						//MessageBox.Show(nic["Description"].ToString()    + "\n" + "Availability = " + Convert.ToInt16(nic["Availability"]).ToString() + "\n" + "AdapterTypeID = " + Convert.ToInt16(nic["AdapterTypeID"]).ToString(), "Description");
					}
					else
					{
						if (nic["MACAddress"] == null)
						{
							MessageBox.Show(nic["NetConnectionID"].ToString() + "\n" + "Availability = " + Convert.ToInt16(nic["Availability"]).ToString() + "\n" + "AdapterTypeID = " + Convert.ToInt16(nic["AdapterTypeID"]).ToString() + "\nMAC is null", "NetConnectionID");
						}
						else
						{
							MessageBox.Show(nic["NetConnectionID"].ToString() + "\n" + "Availability = " + Convert.ToInt16(nic["Availability"]).ToString() + "\n" + "AdapterTypeID = " + Convert.ToInt16(nic["AdapterTypeID"]).ToString()+"\n"+nic["MACAddress"].ToString(), "NetConnectionID");
						}
					}
				}
NetConnectionID gives me the name as it appears in the name column in the Network Connections Control Panel program, but when NetConnectionID is not null the Availability is equal to 8 which means off line.
Very strange. Any input is appreciated.

Thanks,
Einar
Semper ubi sub ubi.
Répondre
Fil
Voir

Click here to load this message in the networking platform