C#调用DOS命令,实现上网拨号功能

零-点 2010-10-26 10:18:11
哪位大虾帮我解决C#调用DOS命令实现上网拨号的程序
有两个按钮 连接和断开,两个文本框填写拨号的登录账号密码,点击连接,调用DOS命令实现网络连接
点击断开,网络断开
请哪位大虾帮我解决这个问题(要详细代码),谢谢!!!

Process p = new Process();
p.StartInfo.WorkingDirectory = "c:\\";
p.StartInfo.FileName = @"cmd.exe";
p.StartInfo.Arguments = "DOS 命令";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string outpuut = p.StandardOutput.ReadToEnd();
p.WaitForExit();

这段代码 有错误,请哪位大虾改正!!
...全文
239 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZengHD 2010-10-26
  • 打赏
  • 举报
回复
private string[] arrCommand = new string[2];
private void FrmMain_Load(object sender, EventArgs e)
{
arrCommand[0] = "rasdial " + m_strADSLName + " /disconnect";
arrCommand[1] = "rasdial " + m_strADSLName + " " + m_strADSLAcc + " " + m_strADSLPwd;
}

private bool ReDial()
{
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;
string strOutput = null;
try
{
p.Start();
foreach (string item in arrCommand)
{
p.StandardInput.WriteLine(item);
}
p.StandardInput.WriteLine("exit");
strOutput = p.StandardOutput.ReadToEnd();
p.WaitForExit();

}
catch (Exception e)
{
strOutput = e.Message;
System.Threading.Thread.Sleep(1000);
return false;
}
finally
{
if (p != null)
p.Close();
}

if (strOutput.IndexOf("选择“错误信息”") >= 0)
{
System.Threading.Thread.Sleep(1000);
return false;
}
return true;
}
零-点 2010-10-26
  • 打赏
  • 举报
回复
这段代码,我点击连接按钮时只闪一下,但拨号连接还是关闭的状态,没有改变
断开一样没反应,请哪位高手帮帮忙
浪子-无悔 2010-10-26
  • 打赏
  • 举报
回复
我只实现过VPN 拨号程序。但是我想原理应该差不多的。
qiuzhengxiang 2010-10-26
  • 打赏
  • 举报
回复
顶了 哥们
qiuzhengxiang 2010-10-26
  • 打赏
  • 举报
回复
有难度,顶,想问下错误的是哪段,是何错误?没想到还能坐板凳
wuyq11 2010-10-26
  • 打赏
  • 举报
回复
零-点 2010-10-26
  • 打赏
  • 举报
回复
如果我这有个连接【宽带连接】,那怎么判断他是否已经连接

110,578

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧