日期:2014-05-18  浏览次数:20906 次

这段代码是什么含义
哪位大侠给解释解释这段代码的含义,最好详细一些。谢谢各位

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Runtime.InteropServices;
using System.Management;

namespace eKanBanClient
{
  public partial class FrmClient : Form
  {
  private const int UdpPort = 8002;
  private const int TcpPort = 8004;
  private const string fgf = "|";
  private UdpClient listener = new UdpClient(UdpPort);
  private bool isClose = false;
  private TcpClient tcpClient;
  private TcpListener tcpListener;
  private string macAddress;
  private string ipAddress;

  public FrmClient()
  {
  InitializeComponent();
  notifyIcon1.Icon = this.Icon;
  notifyIcon1.Text = this.Text;

  ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
  ManagementObjectCollection moc2 = mc.GetInstances();
  foreach (ManagementObject mo in moc2)
  {
  if ((bool)mo["IPEnabled"] == true)
  macAddress = mo["MacAddress"].ToString();
  mo.Dispose();
  }

  foreach (IPAddress ip in Dns.GetHostAddresses(Dns.GetHostName()))
  {
  if (ip.ToString().Length > 7)
  {
  ipAddress = ip.ToString();
  }
  }

   
  tcpListener = new TcpListener(Dns.GetHostAddresses(Dns.GetHostName())[0], TcpPort);
  tcpListener.Start();
  backgroundWorkerTcp.RunWorkerAsync();
  }

  [StructLayout(LayoutKind.Sequential, Pack = 1)]
  internal struct TokPriv1Luid
  {
  public int Count;
  public long Luid;
  public int Attr;
  }

  [DllImport("kernel32.dll", ExactSpelling = true)]
  internal static extern IntPtr GetCurrentProcess();

  [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
  internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

  [DllImport("advapi32.dll", SetLastError = true)]
  internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

  [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
  internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
  ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

  [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  internal static extern bool ExitWindowsEx(int DoFlag, int rea);

  internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
  internal const int TOKEN_QUERY = 0x00000008;
  internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
  internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
  internal const int EWX_LOGOFF = 0x00000000;
&nbs