用c#实现拨号

沿袭上一篇的猥琐方法,贴一段用c#拨号的代码

   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:     }

写这段代码之前,也g了一把,不甚满意,大多数是人云亦云,且所提供代码一般没虾米用处,不过这篇可以参考一下

至于用法嘛,很简单了,而且,最关键的是,完全不需要手动再去点击拨号连接

Tag标签: 自动拨号

posted on 2008-07-11 17:47 micYng 阅读(262) 评论(0)  编辑 收藏 所属分类: Winsock tips


标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2008-07-11 17:51 编辑过
 
 


导航

公告

垃圾Comment,Spam杀无赦!

<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

统计

与我联系

搜索

 

常用链接

留言簿(8)

我参与的团队

我的标签

随笔分类

随笔档案

文章分类

相册

收藏夹

.Net Enterprise Library

.Net Remoting

ASP.NET

Blog Friends:)

C# category

C# forum&blogs

C# Toolkit

CodeSmith Usages

cPP related

Design Pattern

Opensource project

Pervious Blog

Useful tip

积分与排名

最新评论

阅读排行榜

评论排行榜

60天内阅读排行