110,578
社区成员
发帖
与我相关
我的任务
分享
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;
}