Example #1
0
        void btnSet_Click(object sender, EventArgs e)
        {
            try {
                string err = WlanManager.Validate(txtSSID.Text, txtPwd.Text);
                if (err != null)
                {
                    this.Err("错误");
                    return;
                }

                _wlnMgr.SetConnectionSettings(txtSSID.Text, (int)numMaxClients.Value);
                _wlnMgr.SetSecondaryKey(txtPwd.Text);
                _wlnMgr.SetEnable(true);
                if (cmbSharings.SelectedValue != null)
                {
                    if (!_wlnMgr.IsHostedNetworkStarted)
                    {
                        _wlnMgr.StartHostedNetwork();
                    }
                    _icsMgr.EnableIcs((Guid)cmbSharings.SelectedValue, _wlnMgr.HostedNetworkInterfaceGuid);
                }
                this.Info("设置已生效!");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
 /// <summary>
 /// Задаёт пароль точки доступа
 /// </summary>
 /// <param name="password">пароль</param>
 /// <returns>true, если новый пароль успешно применен; false, если возникла ошибка. Вызовите GetLastError(), чтобы получить результат ошибки</returns>
 public bool SetPassword(string password)
 {
     try
     {
         _wlanManager.SetSecondaryKey(password);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        private void StartInternal()
        {
            try
            {
                StopInternal(false);

                Status = WorkingStatus.Starting;

                // system fixes
                SystemTweak.TweakTheSystemNotForced();

                // setting the options
                _wlanManager.SetConnectionSettings(ConfigSsid, ConfigMaxPeers);
                _wlanManager.SetSecondaryKey(ConfigPassword);

                _wlanManager.StartHostedNetwork();

                // save the network id
                _hostedNetworkInterfaceGuid = _wlanManager.HostedNetworkInterfaceGuid;

                var connection = GetIcsToShare();

                if (connection != null)
                {
                    ShareConnection(connection);
                }
                else
                {
                    DisableSharing(true);
                }

                Status = WorkingStatus.Started;
#if TRACE
                LogExceptions.LogTrace(true,
                                       "WLanStart completed, internet is: " + ((connection == null) ? "NULL" : connection.Name));
#endif
            }
            catch (Exception ex)
            {
                LogExceptions.Log(ex);
                Status = WorkingStatus.StartFailed;
            }
        }
Example #4
0
        internal void StartHostedNetwork(string ssid, string key, Guid InterfaceGuid)
        {
            WLAN_HOSTED_NETWORK_REASON WlanHnkReason;

            WlanMgr.QueryConnectionSettings(out string SSID, out uint MaxNumberOfPeers);
            WlanMgr.SetConnectionSettings(ssid, MaxNumberOfPeers);
            WlanMgr.SetSecondaryKey(key, true, true);

            switch (WlanMgr.HostedNetworkState)
            {
            case WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_active:

                try
                {
                    IPhlpapi.FlushIpNetTable(WlanMgr.HostedNetworkGuid);
                    ICSRouter.StopSharing();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}", Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                finally
                {
                    _ = WlanMgr.ForceStop();
                }

                break;

            case WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_unavailable:

                if (!(Advapi32.GetPrivileges() && WlanMgr.AllowHostedNetwork(true)))
                {
                    MessageBox.Show("The hosted network couldn't be started.",
                                    Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    break;
                }
                WlanHnkReason = WlanMgr.ForceStart();
                if (WlanHnkReason != 0)
                {
                    MessageBox.Show(ShowHostedNetworkReason(WlanHnkReason), Text); break;
                }
                while (WlanHnkReason == 0 && !WlanMgr.IsHostedNetworkActive)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
                try { ICSRouter.StartSharing(InterfaceGuid, WlanMgr.HostedNetworkGuid); }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}", Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                break;

            case WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_idle:

                WlanHnkReason = WlanMgr.ForceStart();
                if (WlanHnkReason != 0)
                {
                    MessageBox.Show(ShowHostedNetworkReason(WlanHnkReason), Text); break;
                }
                while (WlanHnkReason == 0 && !WlanMgr.IsHostedNetworkActive)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
                try { ICSRouter.StartSharing(InterfaceGuid, WlanMgr.HostedNetworkGuid); }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}", Text,
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                break;
            }
        }