Beispiel #1
0
 /// <summary>
 /// Displays the configuration.
 /// </summary>
 public void DisplayConfiguration(WindowsNetworkCard config)
 {
     if (config != null)
     {
         txtMacAddress.Text = config.MacAddress;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Gets the current profile.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        internal static WifiProfile GetCurrentProfile(string[] input)
        {
            WifiProfile result = null;

            foreach (string item in input)
            {
                if (item.IndexOf("GUID") >= 0)
                {
                    result = new WifiProfile();
                    string guid = item.Substring(item.IndexOf(":") + 1).Trim();
                    result.InterfaceGuid = "{" + guid.ToUpper() + "}";
                }

                if (item.IndexOf("SSID") >= 0 && item.IndexOf("BSSID") == -1)
                {
                    string ssid = item.Substring(item.IndexOf(":") + 1).Trim();
                    result.SSID = ssid;
                }
            }

            WindowsNetworkCard card = WindowsNetworkCardManager.RefreshStatus(result.InterfaceGuid);

            result.InterfaceMAC         = card.MacAddress;
            result.InterfaceDescription = card.Description;
            result.InterfaceName        = card.Name;

            return(result);
        }
 /// <summary>
 /// Maps the data from WMI.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <param name="card">The card.</param>
 internal static void MapDataFromWMI(ManagementObject input, WindowsNetworkCard card)
 {
     card.WinsEnableLMHostsLookup = (bool)input["WINSEnableLMHostsLookup"];
     card.WinsHostLookupFile      = (string)input["WINSHostLookupFile"];
     card.WinsPrimaryServer       = (string)input["WINSPrimaryServer"];
     card.WinsSecondaryServer     = (string)input["WINSSecondaryServer"];
 }
        /// <summary>
        /// Writes the data into registry.
        /// </summary>
        /// <param name="card">The card.</param>
        public static void WriteDataIntoRegistry(WindowsNetworkCard card)
        {
            RegistryKey regKey = null;

            string sKey = @"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + card.Id;

            try
            {
                regKey = Registry.LocalMachine.OpenSubKey(sKey);

                RegistryUtility.WriteIntValue(RegistryKeyType.LocalMachine, sKey, "EnableDhcp", card.Dhcp ? 1 : 0);

                if (card.Dhcp)
                {
                    String[] temp = { "0.0.0.0" };
                    RegistryUtility.WriteMultiStringValue(RegistryKeyType.LocalMachine, sKey, "IPAddress", temp);
                    RegistryUtility.WriteMultiStringValue(RegistryKeyType.LocalMachine, sKey, "SubnetMask", temp);

                    temp[0] = "";
                    RegistryUtility.WriteMultiStringValue(RegistryKeyType.LocalMachine, sKey, "DefaultGateway", temp);
                }
                else
                {
                    String[] temp = { "0.0.0.0" };

                    temp[0] = card.IpAddress;
                    RegistryUtility.WriteMultiStringValue(RegistryKeyType.LocalMachine, sKey, "IPAddress", temp);
                    temp[0] = card.SubnetMask;
                    RegistryUtility.WriteMultiStringValue(RegistryKeyType.LocalMachine, sKey, "SubnetMask", temp);
                    temp[0] = card.GatewayAddress;
                    RegistryUtility.WriteMultiStringValue(RegistryKeyType.LocalMachine, sKey, "DefaultGateway", temp);
                }

                string dns = "";
                if (!card.DynamicDNS)
                {
                    if (card.Dns.Length >= 1)
                    {
                        dns = card.Dns;
                    }
                    if (card.Dns2.Length >= 1)
                    {
                        dns += "," + card.Dns2;
                    }
                }
                RegistryUtility.WriteStringValue(RegistryKeyType.LocalMachine, sKey, "NameServer", dns);
            }
            finally
            {
                if (regKey != null)
                {
                    regKey.Close();
                }
            }
        }
        /// <summary>
        /// Determines whether [is network card in registry] [the specified card].
        /// </summary>
        /// <param name="card">The card.</param>
        /// <returns>
        ///   <c>true</c> if [is network card in registry] [the specified card]; otherwise, <c>false</c>.
        /// </returns>
        internal static Boolean IsNetworkCardInRegistry(WindowsNetworkCard card)
        {
            if (String.IsNullOrEmpty(card.Id))
            {
                return(false);
            }

            string sKey = @"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + card.Id;

            return(RegistryUtility.Exists(RegistryKeyType.LocalMachine, sKey));
        }
Beispiel #6
0
        /// <summary>
        /// Gets the active wifi profile for card.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <returns></returns>
        public static WifiProfile GetActiveWifiProfileForCard(WindowsNetworkCard card)
        {
            WifiProfile wifi = ActiveWifiProfile;

            if (wifi != null && wifi.InterfaceMAC.Equals(card.MacAddress))
            {
                return(wifi);
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        public void SaveConfiguration(WindowsNetworkCard config)
        {
            if (config == null)
            {
                return;
            }

            config.DynamicDNS = cbDynamicDNS.Checked;
            config.Dns        = txtPrimaryDNS.IpAddress;
            config.Dns2       = txtAlternativeDNS.IpAddress;
        }
Beispiel #8
0
        /// <summary>
        /// Displays the configuration.
        /// </summary>
        public void DisplayConfiguration(WindowsNetworkCard config)
        {
            if (config == null)
            {
                cbDynamicDNS.Checked = true;
                return;
            }

            cbDynamicDNS.Checked        = config.DynamicDNS;
            txtPrimaryDNS.IpAddress     = config.Dns;
            txtAlternativeDNS.IpAddress = config.Dns2;
        }
Beispiel #9
0
        /// <summary>
        /// Saves the configuration.
        /// </summary>
        public void SaveConfiguration(WindowsNetworkCard config)
        {
            if (config == null)
            {
                return;
            }

            config.Dhcp           = cbDHCPEnabled.Checked;
            config.IpAddress      = txtIP.IpAddress;
            config.SubnetMask     = txtSubnetMask.IpAddress;
            config.GatewayAddress = txtDefaultGateway.IpAddress;
        }
Beispiel #10
0
        /// <summary>
        /// Displays the configuration.
        /// </summary>
        public void DisplayConfiguration(WindowsNetworkCard config)
        {
            if (config == null)
            {
                cbDHCPEnabled.Checked = true;
                return;
            }

            cbDHCPEnabled.Checked       = config.Dhcp;
            txtIP.IpAddress             = config.IpAddress;
            txtSubnetMask.IpAddress     = config.SubnetMask;
            txtDefaultGateway.IpAddress = config.GatewayAddress;
        }
Beispiel #11
0
        /// <summary>
        /// Sets the status card.
        /// </summary>
        /// <param name="enabled">if set to <c>true</c> [enabled].</param>
        private static void SetStatusCard(bool enabled)
        {
            WindowsNetworkCard ni = DataModel.SelectedNetworkCard;

            if (ni != null && ni.HardwareName.Length > 0)
            {
                String label = enabled ? "Enabled" : "Disabled";

                bool status = WindowsNetworkCardHelper.SetDeviceStatus(ni, enabled);
                UseCaseLogger.ShowInfo(label + " Network Card " + ni.HardwareName + " (" + status + ")");

                RefreshNetworkCardListStatus();
            }
        }
        /// <summary>
        /// Maps the data from registry.
        /// </summary>
        /// <param name="card">The card.</param>
        internal static void MapDataFromRegistry(WindowsNetworkCard card)
        {
            RegistryKey regKey = null;

            string sKey = @"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" + card.Id;

            try
            {
                regKey              = Registry.LocalMachine.OpenSubKey(sKey);
                card.IpAddress      = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "IPAddress");
                card.GatewayAddress = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DefaultGateway");
                card.SubnetMask     = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "SubnetMask");

                card.Dhcp = RegistryUtility.ReadIntValue(RegistryKeyType.LocalMachine, sKey, "EnableDhcp") == 1 ? true : false;

                string[] dns = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "NameServer").Split(',');

                if (dns.Length >= 1)
                {
                    card.Dns = dns[0];
                }
                if (dns.Length >= 2)
                {
                    card.Dns2 = dns[1];
                }

                card.CurrentIpAddress      = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpIPAddress");
                card.CurrentGatewayAddress = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpDefaultGateway");
                card.CurrentSubnetMask     = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpSubnetMask");

                string[] cdns = RegistryUtility.ReadStringValue(RegistryKeyType.LocalMachine, sKey, "DhcpServer").Split(' ');

                if (cdns.Length >= 1)
                {
                    card.CurrentDns = cdns[0];
                }
                if (cdns.Length >= 2)
                {
                    card.CurrentDns2 = cdns[1];
                }
            }
            finally
            {
                if (regKey != null)
                {
                    regKey.Close();
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Gets the wifi profiles for card.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <returns></returns>
        public static List <WifiProfile> GetWifiProfilesForCard(WindowsNetworkCard card)
        {
            List <WifiProfile> listProfiles = WifiProfiles;
            List <WifiProfile> ret          = new List <WifiProfile>();

            foreach (WifiProfile item in listProfiles)
            {
                if (item.InterfaceName.Equals(card.Name))
                {
                    ret.Add(item);
                }
            }

            return(ret);
        }
Beispiel #14
0
        /// <summary>
        /// Refreshes the wifi combo.
        /// </summary>
        protected void RefreshWifiCombo(NetworkProfile profile)
        {
            WindowsNetworkCard config = profile.NetworkCardInfo;

            if (config == null)
            {
                return;
            }

            // get the correct type from dataModel, cause _configuration.CardType is not affidable
            WindowsNetworkCard     wnc  = DataModel.FindNetworkCard(config.Id);
            WindowsNetworkCardType type = WindowsNetworkCardType.UNKNOWN;

            if (wnc != null)
            {
                type = wnc.CardType;
            }

            // for wifi card
            if (WindowsNetworkCardType.WIRELESS == type)
            {
                WifiProfile currentWifiProfile = WifiProfileManager.GetActiveWifiProfileForCard(config);

                List <WifiProfile> listWifiProfile = WifiProfileManager.GetWifiProfilesForCard(config);

                cbWifiProfile.Items.Clear();
                cbWifiProfile.Items.Add("");
                foreach (WifiProfile item in listWifiProfile)
                {
                    cbWifiProfile.Items.Add(item.SSID);
                }

                // if nic is disable, no wireless profile found. Add the selected profile
                if (listWifiProfile.Count == 0)
                {
                    cbWifiProfile.Items.Add(WifiProfileSSID);
                }

                cbWifi.Checked     = WifiProfileSelected;
                cbWifiProfile.Text = WifiProfileSSID;
            }
            else
            {
                cbWifi.Checked     = false;
                cbWifiProfile.Text = "";
            }
        }
Beispiel #15
0
        /// <summary>
        /// Visualizza una schermata con le informazioni relative ad una scheda di rete.
        /// Nel caso in cui tale finestra sia già presente, viene semplicemente
        /// messa in primo piano.
        /// </summary>
        /// <param name="nic"></param>
        public static void Show(WindowsNetworkCard nic)
        {
            if (nic == null)
            {
                return;
            }
            WindowsNetworkCard temp;

            foreach (FormNetworkCard form in ViewModel.NetworkCardViewList)
            {
                if ((form.Tag is WindowsNetworkCard))
                {
                    temp = (WindowsNetworkCard)form.Tag;

                    if (temp.Id.Equals(nic.Id))
                    {
                        form.TabText = "Network card " + nic.ViewId;
                        form.Text    = "Network card " + nic.ViewId;

                        if (!form.Visible)
                        {
                            form.Show(ViewModel.MainView.Pannello);
                            UseCaseView.ActivateFormNetworkCard(form);
                        }

                        form.Focus();
                        return;
                    }
                }
            }

            FormNetworkCard formApp = new FormNetworkCard();

            // Visualizziamo le informazioni relative alla card
            formApp.Tag = nic;

            //formApp.TabText = "NIC " + nic.ViewId;
            //formApp.Text = "NIC " + nic.ViewId;

            ViewModel.NetworkCardViewList.Add(formApp);
            formApp.Show(ViewModel.MainView.Pannello);
            //formApp.DockState = DockState.Document;
            //formApp.Show();

            formApp.TabText = "Network Card " + nic.ViewId;
            UseCaseView.ActivateFormNetworkCard(formApp);
        }
Beispiel #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetworkProfile"/> class.
        /// </summary>
        public NetworkProfile()
        {
            Id   = 0;
            Name = DEFAULT_PROFILE_NAME;

            NetworkCardInfo = new WindowsNetworkCard();
            ProxyConfig     = new ProxyConfiguration();
            ServiceList     = new List <IWindowsServiceInfo>();
            ExecList        = new List <WindowsExecutable>();
            DriveMapList    = new List <DriveMap>();

            DefaultPrinter = "";

            ImageName = DEFAULT_PROFILE_IMAGE_NAME;

            DisabledNetworkCards = new List <WindowsNetworkCard>();
        }
Beispiel #17
0
        /// <summary>
        /// Refreshes the network adapter info:
        /// - fill the combobox
        /// - select the current nic
        /// - display current nic info
        /// </summary>
        public void RefreshNetworkAdapter()
        {
            ComboBox comboBox = lstNetworkCard;
            List <WindowsNetworkCard> lista = DataModel.NetworkCardList;

            // set combobox
            comboBox.Items.Clear();
            comboBox.Items.Add("NONE");

            foreach (WindowsNetworkCard item in lista)
            {
                string tempName = item.ViewId + " " + item.Name;

                comboBox.Items.Add(tempName);
            }

            comboBox.SelectedIndex = 0;

            // abbiamo una scheda di rete
            if (Profile.NetworkCardInfo != null && Profile.NetworkCardInfo.Id.Length > 0)
            {
                bool bTrovata = false;
                // selezioniamo dalla lista
                int i = 1;
                foreach (WindowsNetworkCard item in lista)
                {
                    if (item.Id.Equals(Profile.NetworkCardInfo.Id))
                    {
                        // l'abbiamo trovata
                        SelectedNetworkCard  = item;
                        bTrovata             = true;
                        txtSelectedCard.Text = item.ViewId + " " + item.Name;
                        int currentNetworkCardIndex = i;
                        lstNetworkCard.SelectedIndex = i;

                        // set current nic as SelectedNic
                        DataModel.SelectedNetworkCard = item;

                        break;
                    }
                    i++;
                }

                DisplaySelectedNetworkCard(true, bTrovata);
            }
        }
        /// <summary>
        /// Applies the specified card.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <returns></returns>
        public static bool Apply(WindowsNetworkCard card)
        {
            bool ret = true;

            if (card.HardwareName.Length > 0)
            {
                WindowsNetworkCardHelper.SetDeviceStatus(card, false);
            }
            WindowsNetworkCardManager.WriteDataIntoRegistry(card);
            WindowsNetworkCardManager.WriteWINSbyWMI(card.Id, card.WinsPrimaryServer, card.WinsSecondaryServer);

            if (card.HardwareName.Length > 0)
            {
                WindowsNetworkCardHelper.SetDeviceStatus(card, true);
            }

            return(ret);
        }
        /// <summary>
        /// Applies the specified card.
        /// </summary>
        /// <param name="card">The card.</param>
        /// <returns></returns>
        public static bool Apply(WindowsNetworkCard card)
        {
            bool ret = true;

            if (card.HardwareName.Length > 0)
            {
                // stop card
                WindowsNetworkCardHelper.SetDeviceStatus(card, false);
            }
            WindowsNetworkCardManager.WriteDataIntoRegistry(card);

            if (card.HardwareName.Length > 0)
            {
                // start card
                WindowsNetworkCardHelper.SetDeviceStatus(card, true);
            }

            return(ret);
        }
Beispiel #20
0
        /// <summary>
        /// Gets the profiles.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns></returns>
        internal static List <WifiProfile> GetProfiles(string[] buffer)
        {
            List <WifiProfile>        ret        = new List <WifiProfile>();
            List <WindowsNetworkCard> cards      = WindowsNetworkCardManager.WindowsNetworkCardList;
            WindowsNetworkCard        currentNic = null;
            WifiProfile currentWifiProfile       = null;

            foreach (string item in buffer)
            {
                if (item.EndsWith(":"))
                {
                    currentNic = null;
                    // first row, get the current nics
                    foreach (WindowsNetworkCard nic in cards)
                    {
                        if (item.Contains(nic.Description + ":"))
                        {
                            currentNic = nic;
                            break;
                        }
                    }
                }
                else if (item.Contains(":") && currentNic != null)
                {
                    currentWifiProfile = new WifiProfile();
                    string ssid = item.Substring(item.IndexOf(":") + 1).Trim();
                    currentWifiProfile.SSID          = ssid;
                    currentWifiProfile.InterfaceGuid = currentNic.Id;

                    currentWifiProfile.InterfaceMAC         = currentNic.MacAddress;
                    currentWifiProfile.InterfaceDescription = currentNic.Description;
                    currentWifiProfile.InterfaceName        = currentNic.Name;

                    ret.Add(currentWifiProfile);
                }
            }

            return(ret);
        }
Beispiel #21
0
        /// <summary>
        /// Copies the specified origin.
        /// </summary>
        /// <param name="origin">The origin.</param>
        /// <returns></returns>
        public static NetworkProfile Copy(NetworkProfile origin)
        {
            NetworkProfile profile = new NetworkProfile();

            profile.Id        = 0;
            profile.Name      = origin.Name;
            profile.ImageName = origin.ImageName;

            profile.NetworkCardInfo = WindowsNetworkCard.Copy(origin.NetworkCardInfo);
            profile.ProxyConfig     = ProxyConfiguration.Copy(origin.ProxyConfig);

            profile.ServiceList = new List <IWindowsServiceInfo>();
            foreach (IWindowsServiceInfo item in profile.ServiceList)
            {
                WindowsServiceInfoImpl temp = (WindowsServiceInfoImpl)item;
                profile.ServiceList.Add(WindowsServiceInfoImpl.Copy(temp));
            }

            profile.ExecList = new List <WindowsExecutable>();
            foreach (WindowsExecutable item in origin.ExecList)
            {
                profile.ExecList.Add(WindowsExecutable.Copy(item));
            }

            profile.DriveMapList = new List <DriveMap>();
            foreach (DriveMap item in origin.DriveMapList)
            {
                profile.DriveMapList.Add(DriveMap.Copy(item));
            }

            profile.DefaultPrinter = origin.DefaultPrinter;

            foreach (WindowsNetworkCard item in origin.DisabledNetworkCards)
            {
                profile.DisabledNetworkCards.Add(WindowsNetworkCard.Copy(item));
            }

            return(profile);
        }
Beispiel #22
0
        /// <summary>
        /// Saves the specified filename.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="document">The document.</param>
        public static bool Save(List <NetworkProfile> profiles, string filename = "Profiles.xml")
        {
            XmlTextWriter writer = new XmlTextWriter(filename, null);

            writer.WriteStartDocument();
            writer.Indentation = 1;
            writer.IndentChar  = '\t';

            writer.WriteStartElement("profiles");

            foreach (NetworkProfile item in profiles)
            {
                writer.WriteStartElement("profile");
                writer.WriteAttributeString("name", item.Name);
                writer.WriteAttributeString("id", item.Id.ToString());
                writer.WriteAttributeString("imageName", item.ImageName);

                {
                    WindowsNetworkCard nic = item.NetworkCardInfo;

                    writer.WriteStartElement("networkcard");

                    if (nic.Id.Length > 0)
                    {
                        XmlUtility.WriteAttributeIfPresent(writer, "id", nic.Id);
                        XmlUtility.WriteAttributeIfPresent(writer, "viewId", nic.ViewId);
                        XmlUtility.WriteAttributeIfPresent(writer, "hardwareName", nic.HardwareName);
                        XmlUtility.WriteAttributeIfPresent(writer, "name", nic.Name);
                        XmlUtility.WriteAttributeIfPresent(writer, "dhcp", nic.Dhcp.ToString());
                        XmlUtility.WriteAttributeIfPresent(writer, "ipAddress", nic.IpAddress);
                        XmlUtility.WriteAttributeIfPresent(writer, "subnetMask", nic.SubnetMask);
                        XmlUtility.WriteAttributeIfPresent(writer, "defaultGateway", nic.GatewayAddress);
                        XmlUtility.WriteAttributeIfPresent(writer, "macAddress", nic.MacAddress);
                        XmlUtility.WriteAttributeIfPresent(writer, "dynamicDns", nic.DynamicDNS.ToString());
                        XmlUtility.WriteAttributeIfPresent(writer, "dns", nic.Dns);
                        XmlUtility.WriteAttributeIfPresent(writer, "dns2", nic.Dns2);
                        XmlUtility.WriteAttributeIfPresent(writer, "winsPrimaryServer", nic.WinsPrimaryServer);
                        XmlUtility.WriteAttributeIfPresent(writer, "winsSecondaryServer", nic.WinsSecondaryServer);
                    }
                    writer.WriteEndElement();
                }

                {
                    ProxyConfiguration proxy = item.ProxyConfig;

                    writer.WriteStartElement("proxy");
                    writer.WriteAttributeString("enabled", proxy.Enabled.ToString());
                    XmlUtility.WriteAttributeIfPresent(writer, "serverAddress", proxy.ServerAddress);
                    XmlUtility.WriteAttributeIfPresent(writer, "port", proxy.Port.ToString());
                    writer.WriteAttributeString("overrideEnabled", proxy.ProxyOverrideEnabled.ToString());
                    XmlUtility.WriteAttributeIfPresent(writer, "proxyOverride", proxy.ProxyOverride.ToString());
                    writer.WriteEndElement();
                }

                {
                    writer.WriteStartElement("driveMaps");

                    List <DriveMap> listDriveMap = item.DriveMapList;

                    foreach (DriveMap itemDriveMap in listDriveMap)
                    {
                        writer.WriteStartElement("driveMap");
                        writer.WriteAttributeString("name", itemDriveMap.Name);
                        XmlUtility.WriteAttributeIfPresent(writer, "drive", itemDriveMap.Drive);
                        XmlUtility.WriteAttributeIfPresent(writer, "description", itemDriveMap.Description);
                        XmlUtility.WriteAttributeIfPresent(writer, "username", itemDriveMap.Username);
                        XmlUtility.WriteAttributeIfPresent(writer, "password", itemDriveMap.Password);
                        XmlUtility.WriteAttributeIfPresent(writer, "realPath", itemDriveMap.RealPath);
                        XmlUtility.WriteAttributeIfPresent(writer, "type", itemDriveMap.Type.ToString());
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }

                {
                    writer.WriteStartElement("applications");

                    List <WindowsExecutable> listExe = item.ExecList;

                    foreach (WindowsExecutable itemExec in listExe)
                    {
                        writer.WriteStartElement("application");
                        writer.WriteAttributeString("name", itemExec.Name);
                        XmlUtility.WriteAttributeIfPresent(writer, "description", itemExec.Description);

                        XmlUtility.WriteAttributeIfPresent(writer, "directory", itemExec.Directory);
                        XmlUtility.WriteAttributeIfPresent(writer, "fileName", itemExec.File);
                        XmlUtility.WriteAttributeIfPresent(writer, "arguments", itemExec.Arguments);
                        XmlUtility.WriteAttributeIfPresent(writer, "wait", itemExec.WaitForExit.ToString());
                        XmlUtility.WriteAttributeIfPresent(writer, "kill", itemExec.Kill.ToString());
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }

                {
                    writer.WriteStartElement("services");

                    List <IWindowsServiceInfo> listService = item.ServiceList;

                    foreach (IWindowsServiceInfo itemService in listService)
                    {
                        writer.WriteStartElement("service");
                        writer.WriteAttributeString("name", itemService.ServiceName);

                        XmlUtility.WriteAttributeIfPresent(writer, "status", itemService.ForcedStatus.ToString());
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }

                // Printer
                {
                    writer.WriteStartElement("printer");
                    XmlUtility.WriteAttributeIfPresent(writer, "defaultPrinter", item.DefaultPrinter);
                    writer.WriteEndElement();
                }

                // disabled nic
                {
                    writer.WriteStartElement("forcedNics");

                    IList <WindowsNetworkCard> listDisabledNics = item.DisabledNetworkCards;

                    foreach (WindowsNetworkCard itemNIC in listDisabledNics)
                    {
                        writer.WriteStartElement("forcedNic");
                        writer.WriteAttributeString("id", itemNIC.Id);
                        writer.WriteAttributeString("hardwareName", itemNIC.HardwareName);
                        writer.WriteEndElement();
                    }

                    writer.WriteEndElement();
                }

                // wifi
                {
                    writer.WriteStartElement("wifi");
                    writer.WriteAttributeString("associatedSSID", item.AssociatedWifiSSID);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();

            writer.WriteEndDocument();
            writer.Close();

            return(true);
        }
Beispiel #23
0
        /// <summary>
        /// Loads the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="imageName">default name of the image.</param>
        /// <returns></returns>
        public static List <NetworkProfile> Load(string fileName, string imageName = NetworkProfile.DEFAULT_PROFILE_IMAGE_NAME)
        {
            List <NetworkProfile> profiles = new List <NetworkProfile>();

            if (!File.Exists(fileName))
            {
                return(null);
            }

            profiles.Clear();
            XmlTextReader reader = null;

            try
            {
                reader = new XmlTextReader(fileName);
                NetworkProfile currentProfile = null;

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:     // The node is an element.
                        switch (reader.Name)
                        {
                        case "profile":
                            currentProfile           = new NetworkProfile();
                            currentProfile.Id        = Int32.Parse(reader.GetAttribute("id"));
                            currentProfile.Name      = reader.GetAttribute("name");
                            currentProfile.ImageName = XmlUtility.ReadAttributeIfPresent(reader, "imageName", imageName);
                            profiles.Add(currentProfile);
                            break;

                        case "networkcard":
                            currentProfile.NetworkCardInfo    = new WindowsNetworkCard();
                            currentProfile.NetworkCardInfo.Id = XmlUtility.ReadAttributeIfPresent(reader, "id", "");

                            currentProfile.NetworkCardInfo.ViewId = XmlUtility.ReadAttributeIfPresent(reader, "viewId", "");
                            currentProfile.NetworkCardInfo.Name   = XmlUtility.ReadAttributeIfPresent(reader, "name", "");

                            currentProfile.NetworkCardInfo.Dhcp           = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "dhcp", Boolean.FalseString));
                            currentProfile.NetworkCardInfo.IpAddress      = XmlUtility.ReadAttributeIfPresent(reader, "ipAddress", "");
                            currentProfile.NetworkCardInfo.SubnetMask     = XmlUtility.ReadAttributeIfPresent(reader, "subnetMask", "");
                            currentProfile.NetworkCardInfo.GatewayAddress = XmlUtility.ReadAttributeIfPresent(reader, "defaultGateway", "");

                            currentProfile.NetworkCardInfo.MacAddress = XmlUtility.ReadAttributeIfPresent(reader, "macAddress", "");
                            currentProfile.NetworkCardInfo.DynamicDNS = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "dynamicDns", Boolean.FalseString));
                            currentProfile.NetworkCardInfo.Dns        = XmlUtility.ReadAttributeIfPresent(reader, "dns", "");
                            currentProfile.NetworkCardInfo.Dns2       = XmlUtility.ReadAttributeIfPresent(reader, "dns2", "");

                            currentProfile.NetworkCardInfo.HardwareName = XmlUtility.ReadAttributeIfPresent(reader, "hardwareName", "");

                            currentProfile.NetworkCardInfo.WinsPrimaryServer   = XmlUtility.ReadAttributeIfPresent(reader, "winsPrimaryServer", "");
                            currentProfile.NetworkCardInfo.WinsSecondaryServer = XmlUtility.ReadAttributeIfPresent(reader, "winsSecondaryServer", "");

                            break;

                        case "proxy":
                            currentProfile.ProxyConfig                      = new ProxyConfiguration();
                            currentProfile.ProxyConfig.Enabled              = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "enabled", Boolean.FalseString));
                            currentProfile.ProxyConfig.ServerAddress        = XmlUtility.ReadAttributeIfPresent(reader, "serverAddress", "");
                            currentProfile.ProxyConfig.Port                 = Int32.Parse(XmlUtility.ReadAttributeIfPresent(reader, "port", "80"));
                            currentProfile.ProxyConfig.ProxyOverrideEnabled = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "overrideEnabled", Boolean.FalseString));
                            currentProfile.ProxyConfig.ProxyOverride        = XmlUtility.ReadAttributeIfPresent(reader, "proxyOverride", "");
                            break;

                        case "application":
                            WindowsExecutable application = new WindowsExecutable();
                            application.Name        = XmlUtility.ReadAttributeIfPresent(reader, "name", "");
                            application.Arguments   = XmlUtility.ReadAttributeIfPresent(reader, "arguments", "");
                            application.Description = XmlUtility.ReadAttributeIfPresent(reader, "description", "");
                            application.Directory   = XmlUtility.ReadAttributeIfPresent(reader, "directory", "");
                            application.File        = XmlUtility.ReadAttributeIfPresent(reader, "fileName", "");
                            application.WaitForExit = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "wait", Boolean.TrueString));
                            application.Kill        = Boolean.Parse(XmlUtility.ReadAttributeIfPresent(reader, "kill", Boolean.TrueString));

                            currentProfile.ExecList.Add(application);
                            break;

                        case "service":
                            WindowsServiceInfoImpl service = new WindowsServiceInfoImpl();

                            service.ServiceName = XmlUtility.ReadAttributeIfPresent(reader, "name", "");

                            string temp = XmlUtility.ReadAttributeIfPresent(reader, "status", ServiceForcedStatus.STOPPED.ToString());

                            if (temp.Equals(ServiceForcedStatus.RUNNING.ToString()))
                            {
                                service.ForcedStatus = ServiceForcedStatus.RUNNING;
                            }
                            else if (temp.Equals(ServiceForcedStatus.STOPPED.ToString()))
                            {
                                service.ForcedStatus = ServiceForcedStatus.STOPPED;
                            }
                            else
                            {
                                service.ForcedStatus = ServiceForcedStatus.NONE;
                            }
                            currentProfile.ServiceList.Add(service);

                            break;

                        case "driveMap":
                            DriveMap drive = new DriveMap();
                            drive.Name        = XmlUtility.ReadAttributeIfPresent(reader, "name", "");
                            drive.Drive       = XmlUtility.ReadAttributeIfPresent(reader, "drive", "");
                            drive.Description = XmlUtility.ReadAttributeIfPresent(reader, "description", "");
                            drive.Username    = XmlUtility.ReadAttributeIfPresent(reader, "username", "");
                            drive.Password    = XmlUtility.ReadAttributeIfPresent(reader, "password", "");
                            drive.RealPath    = XmlUtility.ReadAttributeIfPresent(reader, "realPath", "");
                            string temp1 = XmlUtility.ReadAttributeIfPresent(reader, "type", DriveMapType.MOUNT.ToString());

                            if (temp1.Equals(DriveMapType.MOUNT.ToString()))
                            {
                                drive.Type = DriveMapType.MOUNT;
                            }
                            else
                            {
                                drive.Type = DriveMapType.UNMOUNT;
                            }

                            currentProfile.DriveMapList.Add(drive);
                            break;

                        case "printer":
                            currentProfile.DefaultPrinter = XmlUtility.ReadAttributeIfPresent(reader, "defaultPrinter", "");
                            break;

                        case "forcedNic":
                            // disabled nic
                            WindowsNetworkCard disabledNIC;

                            disabledNIC              = new WindowsNetworkCard();
                            disabledNIC.Id           = XmlUtility.ReadAttributeIfPresent(reader, "id", "");
                            disabledNIC.HardwareName = XmlUtility.ReadAttributeIfPresent(reader, "hardwareName", "");

                            currentProfile.DisabledNetworkCards.Add(disabledNIC);
                            break;

                        case "wifi":
                            // wifi
                            string associatedSSID = XmlUtility.ReadAttributeIfPresent(reader, "associatedSSID", "");

                            currentProfile.AssociatedWifiSSID = associatedSSID;
                            break;
                        }
                        break;

                    case XmlNodeType.Text:     //Display the text in each element.
                        Console.WriteLine(reader.Value);
                        break;

                    case XmlNodeType.EndElement:     //Display the end of the element.
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(profiles);
        }
        /// <summary>
        /// Gets the list from WMI.
        /// </summary>
        /// <returns></returns>
        protected static List <WindowsNetworkCard> GetListFromWMI()
        {
            SortedDictionary <string, WindowsNetworkCard> dictionary = new SortedDictionary <string, WindowsNetworkCard>();

            List <WindowsNetworkCard> lista = new List <WindowsNetworkCard>();

            SelectQuery query = new SelectQuery("Win32_NetworkAdapter", "GUID is not null");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);

            // 1 - Create list of cards
            WindowsNetworkCard card;

            // create network card objects
            foreach (ManagementObject item in search.Get())
            {
                WmiNetworkAdapter adapter = new WmiNetworkAdapter(item);

                if (adapter.Name.ToUpper().Contains("Microsoft Virtual WiFi Miniport Adapter".ToUpper()))
                {
                    continue;
                }
                ;

                card = new WindowsNetworkCard();

                //GUID is supported in win7
                card.Id = adapter.GUID;

                card.ViewId              = fixViewId(adapter.Caption);
                card.Name                = adapter.Name;
                card.HardwareName        = fixHardwareName(adapter.Caption);
                card.Enabled             = adapter.NetEnabled;
                card.NetConnectionStatus = adapter.NetConnectionStatus;
                card.Index               = adapter.Index;

                card.MaxSpeed = adapter.Speed;


                card.PnpDeviceId = adapter.PNPDeviceID;

                card.Description = adapter.NetConnectionID;
                card.MacAddress  = adapter.MACAddress;
                //  http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx

                /*
                 *  "Ethernet 802.3"
                 *  "Token Ring 802.5"
                 *  "Fiber Distributed Data Interface (FDDI)"
                 *  "Wide Area Network (WAN)"
                 *  "LocalTalk"
                 *  "Ethernet using DIX header format"
                 *  "ARCNET"
                 *  "ARCNET (878.2)"
                 *  "ATM"
                 *  "Wireless"
                 *  "Infrared Wireless"
                 *  "Bpc"
                 *  "CoWan"
                 *  "1394"
                 * */

                card.AdapterType = adapter.AdapterType;

                if (!IsNetworkCardInRegistry(card))
                {
                    continue;
                }
                // 2 - get more info from registry
                MapDataFromRegistry(card);
                dictionary[card.Id] = card;
            }

            // 2 - Get more info
            String      id;
            SelectQuery query2 = new SelectQuery("Win32_NetworkAdapterConfiguration", "IPEnabled='TRUE'");
            ManagementObjectSearcher search2 = new ManagementObjectSearcher(query2);

            // find by index
            foreach (ManagementObject item in search2.Get())
            {
                WmiNetworkAdapterConfiguration adapterConfigurator = new WmiNetworkAdapterConfiguration(item);
                id = adapterConfigurator.SettingID;

                // only if card is present
                if (dictionary.ContainsKey(id))
                {
                    card = dictionary[id];

                    if (card != null)
                    {
                        card.WinsEnableLMHostsLookup = adapterConfigurator.WINSEnableLMHostsLookup;
                        card.WinsHostLookupFile      = adapterConfigurator.WINSHostLookupFile;
                        card.WinsPrimaryServer       = adapterConfigurator.WINSPrimaryServer;
                        card.WinsSecondaryServer     = adapterConfigurator.WINSSecondaryServer;
                    }
                }
            }

            lista.AddRange(dictionary.Values);

            return(lista);
        }
Beispiel #25
0
        /// <summary>
        /// Autodetects the network profile. For the moment it works only for wifi connections!
        /// If no connections found, it return null.
        /// Use
        ///     WindowsNetworkCardManager.EnabledWindowsNetworkCardList
        ///     WifiProfileManager.ActiveWifiProfile;
        /// </summary>
        ///
        /// <param name="profiles">profiles.</param>
        /// <returns></returns>
        public static NetworkProfile AutodetectNetworkProfile(List <NetworkProfile> profiles)
        {
            NetworkProfileHelper.FireNotifyEvent("Start autodetect");
            if (profiles == null || profiles.Count == 0)
            {
                NetworkProfileHelper.FireNotifyEvent("There's no profiles");
                NetworkProfileHelper.FireNotifyEvent("End autodetect");
                return(null);
            }
            // initial setup for cards
            SetupNetworkCardForAutodetect(profiles);

            NetworkProfile selectedProfile = null;

            // one or more card (not only wifi)
            // wifi connected,
            WifiProfile currentWifiProfile = WifiProfileManager.ActiveWifiProfile;

            // enable card
            List <WindowsNetworkCard> enabledCardList = WindowsNetworkCardManager.EnabledWindowsNetworkCardList;

            if (enabledCardList.Count == 1 && enabledCardList[0].CardType == WindowsNetworkCardType.WIRELESS && currentWifiProfile.SSID != null)
            {
                WindowsNetworkCard card = enabledCardList[0];
                // only a wifi connection avaible
                foreach (NetworkProfile item in profiles)
                {
                    // select if card is right and (ssid is right or for that profile there's no ssid)
                    if (item.NetworkCardInfo.Id.Equals(card.Id) && (currentWifiProfile.SSID.Equals(item.AssociatedWifiSSID) || string.IsNullOrWhiteSpace(item.AssociatedWifiSSID)))
                    {
                        // ok, we found it!!!
                        selectedProfile = item;

                        if (!string.IsNullOrWhiteSpace(item.AssociatedWifiSSID))
                        {
                            NetworkProfileHelper.FireNotifyEvent("The card " + card.Name + " are connected with right SSID (" + currentWifiProfile.SSID + ")");
                        }
                        NetworkProfileHelper.FireNotifyEvent("Selected profile " + item.Name + " without do anything else!!");
                        break;
                    }
                }
            }
            else
            {
                // order list by maxSpeed
                //enabledCardList.Sort(CompareCardBySpeed);

                // if there's no enabled card, it's a problem!
                if (enabledCardList.Count == 0)
                {
                    NetworkProfileHelper.FireNotifyEvent("No card enabled, found"); return(null);
                }

                List <NetworkProfile> enabledProfileList = FindValidOrderedNetworkProfiles(profiles, enabledCardList, currentWifiProfile);

                // assert: enabledProfile contains the right profiles. Now we have to test it.
                // the first with ping ok it's ok!
                bool pingOk;
                foreach (NetworkProfile item in enabledProfileList)
                {
                    NetworkProfileHelper.FireNotifyEvent("Start analizing profile " + item.Name + " with card " + item.NetworkCardInfo.Name);
                    //WindowsNetworkCardHelper.SetDeviceStatus(item.NetworkCardInfo, false);
                    NetworkProfileHelper.RunDisableNetworkCardsSetup(item);
                    NetworkProfileHelper.RunNetworkCardSetup(item);

                    // wait for a while
                    //NetworkProfileHelper.FireNotifyEvent("Wait " + (WAIT_BEFORE_PING) + " ms.");
                    //System.Threading.Thread.Sleep(WAIT_BEFORE_PING);
                    WindowsNetworkCardEventHandler eventHandler = new WindowsNetworkCardEventHandler(item.NetworkCardInfo);

                    eventHandler.WaitUntilNetworkCardIsUp();
                    //WaitUntilNetworkCardIsUp(item.NetworkCardInfo);

                    NetworkProfileHelper.FireNotifyEvent("Wait " + (WAIT_BEFORE_PING) + " ms.");
                    System.Threading.Thread.Sleep(WAIT_BEFORE_PING);

                    WindowsNetworkCard card = WindowsNetworkCardManager.RefreshStatus(item.NetworkCardInfo.Id);

                    if (card.CardType == WindowsNetworkCardType.WIRELESS)
                    {
                        // get current wifi profile only for wifi card
                        currentWifiProfile = WifiProfileManager.GetActiveWifiProfileForCard(card);

                        if (currentWifiProfile != null && currentWifiProfile.SSID.Equals(item.AssociatedWifiSSID) && card.NetConnectionStatus == 2)
                        {
                            // ok, we found it!!!
                            selectedProfile = item;
                            NetworkProfileHelper.FireNotifyEvent("The card " + card.Name + " are connected with right SSID (" + currentWifiProfile.SSID + ")");
                            NetworkProfileHelper.FireNotifyEvent("Selected profile " + item.Name + " without do anything else!!");
                            break;
                        }
                    }
                    else
                    {
                        pingOk = false;

                        NetworkProfileHelper.FireNotifyEvent("The card " + card.Name + " are in status " + card.NetConnectionStatus);
                        // test both static config or dynamic config
                        pingOk = PingHelper.RunPing(card.GatewayAddress);
                        pingOk = pingOk || PingHelper.RunPing(card.CurrentGatewayAddress);

                        NetworkProfileHelper.FireNotifyEvent("For card " + card.Name + " and profile " + item.Name + ", ping to gateway are " + pingOk);

                        if (pingOk)
                        {
                            selectedProfile = item;
                            NetworkProfileHelper.FireNotifyEvent("Selected profile " + item.Name + "!!");
                            break;
                        }
                    }

                    NetworkProfileHelper.FireNotifyEvent("Stop analizing profile " + item.Name + ", go to next profile");
                }

                // restore initial enabled card
                if (selectedProfile == null)
                {
                    NetworkProfileHelper.FireNotifyEvent("No profile found, so restore status card");
                    foreach (WindowsNetworkCard item in enabledCardList)
                    {
                        NetworkProfileHelper.FireNotifyEvent("Enable card " + item.Name);
                        WindowsNetworkCardHelper.SetDeviceStatus(item, true);
                    }
                }
            }

            NetworkProfileHelper.FireNotifyEvent("End autodetect");
            return(selectedProfile);
        }
Beispiel #26
0
        /// <summary>
        /// Select NIC selected from listview and fill other fields.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void SelectNetworkCard()
        {
            NetworkProfile profile = Profile;
            // cerchiamo viewId
            string work = lstNetworkCard.Text;

            if (work.Equals(UseCaseProfile.NEW_NIC_NAME))
            {
            }
            else
            {
                int i1 = work.IndexOf("[");

                if (i1 >= 0)
                {
                    int i2 = work.IndexOf("]", i1);

                    work = i2 > 0 ? work.Substring(i1, i2 + 1) : work;
                }
                if (work.Length > 0)
                {
                    List <WindowsNetworkCard> lista = DataModel.NetworkCardList;

                    // lo facciamo solo se la card è diversa
                    if (profile.NetworkCardInfo == null || !profile.NetworkCardInfo.ViewId.Equals(work))
                    {
                        foreach (WindowsNetworkCard item in lista)
                        {
                            if (item.ViewId.Equals(work))
                            {
                                SelectedNetworkCard = item;

                                if (item.CardType == WindowsNetworkCardType.WIRELESS)
                                {
                                    // if present get the active profile
                                    WifiProfile wifiProfile = WifiProfileManager.GetActiveWifiProfileForCard(item);
                                    if (wifiProfile != null)
                                    {
                                        Profile.AssociatedWifiSSID = wifiProfile.SSID;

                                        wifiProfileControl.WifiProfileSelected = true;
                                        wifiProfileControl.WifiProfileSSID     = wifiProfile.SSID;
                                        wifiProfileControl.DisplayConfiguration(Profile);
                                    }
                                }


                                ipControl.DisplayConfiguration(item);
                                dnsConfiguration.DisplayConfiguration(item);
                                macAddressControl.DisplayConfiguration(item);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    SelectedNetworkCard = null;
                }
            }
            DisplaySelectedNetworkCard(false, true);
        }
Beispiel #27
0
        /// <summary>
        /// Displays the selected network card.
        /// </summary>
        /// <param name="found">if set to <c>true</c> [found].</param>
        private void DisplaySelectedNetworkCard(bool getInfoFromProfile, bool found)
        {
            string temp;

            WindowsNetworkCard tempCard;

            if (getInfoFromProfile)
            {
                tempCard = Profile.NetworkCardInfo;
            }
            else
            {
                tempCard = SelectedNetworkCard;
            }

            if (SelectedNetworkCard != null)
            {
                if (!found)
                {
                    txtSelectedCard.ForeColor = Color.Red;
                }
                else
                {
                    txtSelectedCard.ForeColor = Color.Black;
                }
                temp = SelectedNetworkCard.ViewId + " " + SelectedNetworkCard.Name;

                WindowsNetworkCard nic = new WindowsNetworkCard();

                // visualizziamo i dati della configurazione
                nic.IpAddress      = tempCard.IpAddress;
                nic.SubnetMask     = tempCard.SubnetMask;
                nic.GatewayAddress = tempCard.GatewayAddress;
                nic.Dns            = tempCard.Dns;
                nic.Dns2           = tempCard.Dns2;
                nic.Dhcp           = tempCard.Dhcp;
                nic.DynamicDNS     = tempCard.DynamicDNS;
                nic.MacAddress     = tempCard.MacAddress;
                nic.HardwareName   = tempCard.HardwareName;
                nic.Name           = tempCard.Name;
                nic.Id             = tempCard.Id;
                nic.CardType       = tempCard.CardType;

                ipControl.DisplayConfiguration(nic);
                dnsConfiguration.DisplayConfiguration(nic);

                // assign wifi before config
                wifiProfileControl.WifiProfileSelected = false;
                wifiProfileControl.WifiProfileSSID     = "";
                if (Profile.AssociatedWifiSSID != null && Profile.AssociatedWifiSSID.Length > 0)
                {
                    wifiProfileControl.WifiProfileSelected = true;
                    wifiProfileControl.WifiProfileSSID     = Profile.AssociatedWifiSSID;
                }

                macAddressControl.DisplayConfiguration(nic);
            }
            else
            {
                temp = "";
            }
            txtSelectedCard.Text = temp;
        }
Beispiel #28
0
 /// <summary>
 /// Selects the network card.
 /// </summary>
 /// <param name="card">The card.</param>
 public static void SelectNetworkCard(WindowsNetworkCard card)
 {
     DataModel.SelectedNetworkCard = card;
     UseCaseLogger.ShowInfo("Selected network card " + card.Name);
 }
        /// <summary>
        /// Gets the list from WMI.
        /// </summary>
        /// <returns></returns>
        protected static List <WindowsNetworkCard> GetListFromWMI()
        {
            SortedDictionary <uint, WindowsNetworkCard> dictionary = new SortedDictionary <uint, WindowsNetworkCard>();

            List <WindowsNetworkCard> lista = new List <WindowsNetworkCard>();

            SelectQuery query = new SelectQuery("Win32_NetworkAdapter");//, "GUID is not null");
            ManagementObjectSearcher search = new ManagementObjectSearcher(query);

            // 1 - Create list of cards
            WindowsNetworkCard card;

            // create network card objects
            foreach (ManagementObject item in search.Get())
            {
                WmiNetworkAdapter adapter = new WmiNetworkAdapter(item);


                /*if (String.IsNullOrEmpty(adapter.GUID))
                 * {
                 *  continue;
                 * }*/


                if (adapter.Name.ToUpper().Contains("Microsoft Virtual WiFi Miniport Adapter".ToUpper()))
                {
                    continue;
                }
                ;

                card = new WindowsNetworkCard();

                //GUID is not supported in winxp
                //card.Id = adapter.GUID;

                card.ViewId       = fixViewId(adapter.Caption);
                card.Name         = adapter.Name;
                card.HardwareName = fixHardwareName(adapter.Caption);
                //card.Enabled = adapter.NetEnabled;
                card.NetConnectionStatus = adapter.NetConnectionStatus;
                card.Index = adapter.Index;

                card.MaxSpeed = adapter.MaxSpeed;

                card.PnpDeviceId = adapter.PNPDeviceID;

                //http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx

                /*
                 * "Ethernet 802.3"
                 *  "Token Ring 802.5"
                 *  "Fiber Distributed Data Interface (FDDI)"
                 *  "Wide Area Network (WAN)"
                 *  "LocalTalk"
                 *  "Ethernet using DIX header format"
                 *  "ARCNET"
                 *  "ARCNET (878.2)"
                 *  "ATM"
                 *  "Wireless"
                 *  "Infrared Wireless"
                 *  "Bpc"
                 *  "CoWan"
                 *  "1394"
                 * */
                card.AdapterType = adapter.AdapterType;

                card.Description = adapter.NetConnectionID;
                card.MacAddress  = adapter.MACAddress;

                dictionary[card.Index] = card;
            }

            // 2 - Get more info
            String      id;
            SelectQuery query2 = new SelectQuery("Win32_NetworkAdapterConfiguration");
            ManagementObjectSearcher search2 = new ManagementObjectSearcher(query2);

            // find by index
            foreach (ManagementObject item in search2.Get())
            {
                WmiNetworkAdapterConfiguration adapterConfigurator = new WmiNetworkAdapterConfiguration(item);
                id = adapterConfigurator.SettingID;

                Debug.WriteLine("Config for " + adapterConfigurator.SettingID);

                card = dictionary[adapterConfigurator.Index];

                if (card != null)
                {
                    // set the uid
                    card.Id = adapterConfigurator.SettingID;
                    if (!IsNetworkCardInRegistry(card))
                    {
                        // it's not a network card
                        dictionary.Remove(adapterConfigurator.Index);
                        Debug.WriteLine("Config for " + adapterConfigurator.Caption + " is not a network card");
                        continue;
                    }

                    card.WinsEnableLMHostsLookup = adapterConfigurator.WINSEnableLMHostsLookup;
                    card.WinsHostLookupFile      = adapterConfigurator.WINSHostLookupFile;
                    card.WinsPrimaryServer       = adapterConfigurator.WINSPrimaryServer;
                    card.WinsSecondaryServer     = adapterConfigurator.WINSSecondaryServer;
                }
                else
                {
                    Debug.WriteLine("Config for " + adapterConfigurator.Caption + " not found");
                }
            }

            // every item withoud id is not a valid adapter
            foreach (WindowsNetworkCard item in dictionary.Values)
            {
                if (!String.IsNullOrEmpty(item.Id))
                {
                    MapDataFromRegistry(item);
                    lista.Add(item);
                }
            }



            return(lista);
        }