Beispiel #1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            try
            {
                _netsh = new NetShareHost();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "NetShare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }

            if (!CheckServices())
            {
                Application.Exit();
                return;
            }

            Configuration conf = new Configuration();

            conf.Read();

            txtSSID.Text     = _netsh.GetConnectionSettings().SSID;
            txtPassword.Text = _netsh.GetPassword();

            var conns = _netsh.GetSharableConnections();

            foreach (var item in conns)
            {
                cmbShareAdapter.Items.Add(item);
            }

            SharableConnection sharedConnection = null;

            sharedConnection = (from c in conns
                                where c.Guid == conf.SharedConnection
                                select c).FirstOrDefault();
            if (sharedConnection == null)
            {
                sharedConnection = conns.First();
            }

            for (int i = 0; i < cmbShareAdapter.Items.Count; i++)
            {
                if ((cmbShareAdapter.Items[i] as SharableConnection).Guid == sharedConnection.Guid)
                {
                    cmbShareAdapter.SelectedIndex = i;
                    break;
                }
            }

            chckIsAutostart.Checked = conf.IsAutostart;
            UpdateControls();
            UpdateConnectionsListSafe();

            _netsh.ConnectionsListChanged += _netsh_OnConnectionsListChanged;
            _netsh.HostedNetworkStarted   += _netsh_HostedNetworkStarted;
            _netsh.HostedNetworkStopped   += _netsh_HostedNetworkStopped;
        }
Beispiel #2
0
 public NetShareService()
 {
     _netshHost = new NetShareHost();
     InitializeComponent();
 }
Beispiel #3
0
 private void _netsh_OnConnectionsListChanged(NetShareHost hostedNetworkManager)
 {
     UpdateConnectionsListSafe();
 }
Beispiel #4
0
 private void _netsh_HostedNetworkStopped(NetShareHost hostedNetworkManager)
 {
     StartStopThreadSafe(false);
 }