zoukankan      html  css  js  c++  java
  • 怎么样用ASP程序或其他程序语言断开网络连接

     

    以前写的C#代码,下面是拨号和断开的函数【在Vista/XP系统中,网通拨号测试通过,不需要安装网通的拨号客户端】:

      private static Mutex mutex = new Mutex();
      private Process dailer = new Process();

      int Desc;
      //Creating the extern function...
      [DllImport("wininet.dll")]
      private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
      //Creating a function that uses the API function...
      //if out parameter returns 18 then fail,if 81 then success 
      public void IsConnectedToInternet()
      {
      InternetGetConnectedState(out Desc, 0);
      }

      private void StopDailer()
      {
     
      while (Desc == 81)
      {
      lock (dailer)
      {
      if (!IsAlive("rundll32"))
      {
      mutex.WaitOne();
      dailer.StartInfo.FileName = "rundll32.exe";
      dailer.StartInfo.Arguments = "iedkcs32.dll CloseRASConnections";
      dailer.Start();
      //Thread.Sleep(1000);
      mutex.ReleaseMutex();
      }
     
      }
      IsConnectedToInternet();
      }
      dailer.Close();
      }

      private void StartDailer()
      {
     
      while (Desc != 81)
      {
      lock (dailer)
      {
      if (!IsAlive("rasdial"))
      {
      mutex.WaitOne();
      dailer.StartInfo.FileName = "rasdial.exe";
       //txtDail.Text宽带拨号的名称、txtName.Text宽带用户名【注意:是加密过的,不是你的原始用户名】、txtPWD.Text宽带用户密码
      dailer.StartInfo.Arguments = txtDail.Text.Trim() + " " + txtName.Text.Trim() + " " + txtPWD.Text.Trim();
      dailer.Start();
      mutex.ReleaseMutex();
      }
     
      //Thread.Sleep(1000);
      }
      IsConnectedToInternet();
      }
      dailer.Close();
      }
     private bool IsAlive(string name)
      {
      Process[] ps = Process.GetProcessesByName(name);
      if (ps.Length > 0)
      {
      return true;
      }
      else
      {
      return false;
      }
      }

  • 相关阅读:
    CSP201412-2:Z字形扫描
    CSP201409-2:画图
    CSP201403-2:窗口
    CSP201312-2:ISBN号码
    CSP201709-1:打酱油
    CSP201703-1:分蛋糕
    CSP201612-1:中间数
    LOAM笔记及A-LOAM源码阅读
    特征值、特征向量与PCA算法
    欧几里得与区域生长算法
  • 原文地址:https://www.cnblogs.com/liufei88866/p/1516442.html
Copyright © 2011-2022 走看看