日期:2014-05-18 浏览次数:21462 次
http://www.cnblogs.com/lovesanni/archive/2008/07/11/1240923.html
1: class AutoDialer
   2:     {
   3:         public void Connect(string connectionName, string user, string pass)
   4:         {
   5:             string arg = string.Format("rasdial \"{0}\" {1} {2}", connectionName, user, pass);
   6:             InvokeCmd(arg);
   7:         }
   8:  
   9:         public void Disconnect(string connectionName)
  10:         {
  11:             string arg = string.Format("rasdial \"{0}\" /disconnect", connectionName);
  12:             InvokeCmd(arg);
  13:         }
  14:  
  15:         private static string InvokeCmd(string cmdArgs)
  16:         {
  17:             Process p = new Process();
  18:             p.StartInfo.FileName = "cmd.exe";
  19:             p.StartInfo.UseShellExecute = false;
  20:             p.StartInfo.RedirectStandardInput = true;
  21:             p.StartInfo.RedirectStandardOutput = true;
  22:             p.StartInfo.RedirectStandardError = true;
  23:             p.StartInfo.CreateNoWindow = true;
  24:             p.Start();
  25:  
  26:             p.StandardInput.WriteLine(cmdArgs);
  27:             p.StandardInput.WriteLine("exit");
  28:  
  29:             return p.StandardOutput.ReadToEnd();
  30:         }
  31:     }
------解决方案--------------------
不懂,UP~
------解决方案--------------------
帮顶,顺便学习。。