Ejemplo n.º 1
0
        static void DisableInternetSharing()
        {
            try
            {
                var currentShare = IcsManager.GetCurrentlySharedConnections();
                if (!currentShare.Exists)
                {
                    return;
                }

                IcsManager.ShareConnection(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Ejemplo n.º 2
0
        static bool EnableInternetSharing(
            string SrcNetName,
            string HostedNetName,
            bool bForce)
        {
            string err = null;

            try
            {
                do
                {
                    var SrcNet = IcsManager.FindConnectionByIdOrName(SrcNetName);
                    if (SrcNet == null)
                    {
                        err = "Connection not found: " + SrcNetName;
                        break;
                    }

                    var HostedNet = IcsManager.FindConnectionByIdOrName(HostedNetName);
                    if (HostedNet == null)
                    {
                        err = "Could not find network " + HostedNetName;
                        break;
                    }

                    IcsManager.ShareConnection(
                        SrcNet,
                        HostedNet);
                } while (false);
            }
            catch (Exception ex)
            {
                err = ex.Message;
            }

            if (!string.IsNullOrEmpty(err))
            {
                MessageBox.Show(err, "Error");
                return(false);
            }
            return(true);
        }