您的位置:首页 > 编程语言 > C#

用C#实现宽带重新拨号

2012-09-23 15:47 519 查看
我们做一些软件的时候常常要用到换IP的操作,其实简单的换IP的方法就是重新拨号啊,下面就是我实践成功的重新拨号的代码,很简单的,是一个单独的类。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;//诊断,调用进程

namespace QQ号批量注册
{
class ADSLHelper
{

public void Connect(string connectionName, string user, string pass)
{
string arg = string.Format("rasdial \"{0}\" {1} {2}", connectionName, user, pass);
InvokeCmd(arg);
}
public void Disconnect(string connectionName)
{
string arg = string.Format("rasdial \"{0}\" /disconnect", connectionName);
InvokeCmd(arg);
}
public static string InvokeCmd(string cmdArgs)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdArgs);
p.StandardInput.WriteLine("exit");
return p.StandardOutput.ReadToEnd();
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: