コード例 #1
0
 public ChangeRemoteDesktopPort()
 {
     InitializeComponent();
     if (!CheckPermission.IsAdmin())
     {
         AdminButton.AddShieldToButton(button1);
     }
 }
コード例 #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (CheckPermission.IsAdmin())
     {
         ChangePort();
     }
     else
     {
         AdminButton.RestartElevated();
     }
 }
コード例 #3
0
        public bool Start(int interval = 1000)
        {
            #region 启动系统性能计数器统计

            bool isSucceed;
            try
            {
                isSucceed = NetFlow.Start(interval);
                NetFlow.DataMonitorEvent += DataMonitorEvent;
                IsNetFlowRun              = true;
            }
            catch
            {
                return(false);
            }

            if (!isSucceed)
            {
                return(false);
            }

            #endregion

            #region 启动Socket包统计
            if (CheckPermission.IsAdmin())
            {
                var hosts = NetCardInfoTool.GetIPv4Address();
                AllIPv4Address = NetCardInfoTool.GetAllIPv4Address();
                foreach (var host in hosts)
                {
                    try
                    {
                        var p = new NetPacketTool(host);
                        p.NewPacket += NewPacketEvent;
                        p.Start();
                        NetPacketList.Add(p);
                    }
                    catch
                    {
                        // ignored
                    }
                }
                if (ListTool.HasElements(NetPacketList))
                {
                    IsNetPacketRun = true;
                }
            }
            #endregion

            return(true);
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the PacketMonitor class.
 /// </summary>
 /// <param name="ip">The interface on which to listen for IP packets.</param>
 /// <exception cref="NotSupportedException">The operating system does not support intercepting packets.</exception>
 public NetPacketTool(IPAddress ip)
 {
     // make sure the user runs this program on Windows NT 5.0 or higher
     if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version.Major < 5)
     {
         throw new NotSupportedException(@"This program requires Windows 2000, Windows XP or Windows .NET Server!");
     }
     // make sure the user is an Administrator
     if (!CheckPermission.IsAdmin())
     {
         throw new NotSupportedException(@"This program can only be run by administrators!");
     }
     IP     = ip;
     Buffer = new byte[65535];
 }