コード例 #1
0
        /// <summary>
        /// Запускает точку доступа с указанным адаптером для ICS
        /// </summary>
        /// <param name="sharedConnectionGuid">адаптер для ICS</param>
        /// <returns>true, если точка доступа успешно запущена; false, если возникла ошибка. Вызовите GetLastError(), чтобы получить результат ошибки</returns>
        public bool Start(SharableConnection sharedConnection)
        {
            try
            {
                Stop();

                _wlanManager.StartHostedNetwork();

                System.Threading.Thread.Sleep(1000);

                if (sharedConnection != null)
                {
                    if (sharedConnection.Guid != Guid.Empty)
                    {
                        if (_icsManager.SharingInstalled)
                        {
                            _icsManager.DisableIcsOnAll();

                            var privateConnectionGuid = _wlanManager.HostedNetworkInterfaceGuid;

                            if (privateConnectionGuid == Guid.Empty)
                            {
                                // If the GUID for the Hosted Network Adapter isn't return properly,
                                // then retrieve it by the DeviceName.

                                privateConnectionGuid = (from c in _icsManager.Connections
                                                         where c.Props.DeviceName.ToLowerInvariant().Contains("microsoft virtual wifi miniport adapter") ||                                                      // Windows 7
                                                         c.Props.DeviceName.ToLowerInvariant().Contains("microsoft hosted network virtual adapter")                                                            // Windows 8
                                                         select c.Guid).FirstOrDefault();
                                // Note: For some reason the DeviceName can have different names, currently it checks for the ones that I have identified thus far.

                                if (privateConnectionGuid == Guid.Empty)
                                {
                                    // Device still now found, so throw exception so the message gets raised up to the client.
                                    throw new Exception("Virtual Wifi device not found!\n\nNeither \"Microsoft Hosted Network Virtual Adapter\" or \"Microsoft Virtual Wifi Miniport Adapter\" were found.");
                                }
                            }

                            _icsManager.EnableIcs(sharedConnection.Guid, privateConnectionGuid);

                            _currentSharedConnection = sharedConnection;
                        }
                    }
                }
                else
                {
                    _currentSharedConnection = null;
                }

                return(true);
            }
            catch (Exception ex)
            {
                _lastErrorMessage = ex.Message;
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Запускает точку доступа с указанным адаптером для ICS
        /// </summary>
        /// <param name="sharedConnectionGuid">GUID адаптера для ICS</param>
        /// <returns>true, если точка доступа успешно запущена; false, если возникла ошибка. Вызовите GetLastError(), чтобы получить результат ошибки</returns>
        public bool Start(Guid sharedConnectionGuid)
        {
            var conns = GetSharableConnections();
            SharableConnection sharedConnection = null;

            sharedConnection = (from c in conns
                                where c.Guid == sharedConnectionGuid
                                select c).FirstOrDefault();
            if (sharedConnection == null)
            {
                return(false);
            }
            return(Start(sharedConnection));
        }