在我的应用程序中,我通过命令提示符窗口设置了一个 vpn 连接,输出将放在一个文本框中。它会自我刷新,因此当它从命令提示符获取新行时会添加一个新行。
输出将是这样的。
> Microsoft Windows [versie 6.1.7601] Copyright (c) 2009 Microsoft
> Corporation. Alle rechten voorbehouden.
>
> C:\Users\...\Desktop>rasdial.exe VPN username password
> Verbinding maken met VPN...
> Gebruikersnaam en wachtwoord controleren...
> Uw computer wordt in het netwerk geregistreerd...
> Verbinding gemaakt met VPN Opdracht voltooid.
>
> C:\Users\Helpdesk\Desktop>exit
我怎样才能删除 Microsoft Windows 部分,所以我只有这个。
rasdial.exe VPN username password
Verbinding maken met VPN...
Gebruikersnaam en wachtwoord controleren...
Uw computer wordt in het netwerk geregistreerd...
Verbinding gemaakt met VPN Opdracht voltooid.
这是我添加单独行的代码。
private void ConnectVPN()
{
CheckForIllegalCrossThreadCalls = false;
Process CMDprocess = new Process();
System.Diagnostics.ProcessStartInfo StartInfo = new System.Diagnostics.ProcessStartInfo();
StartInfo.FileName = "cmd";
StartInfo.CreateNoWindow = true;
StartInfo.RedirectStandardInput = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.UseShellExecute = false;
CMDprocess.StartInfo = StartInfo;
CMDprocess.Start();
System.IO.StreamReader SR = CMDprocess.StandardOutput;
System.IO.StreamWriter SW = CMDprocess.StandardInput;
SW.WriteLine("rasdial.exe " + comboBox1.Text + " " + loginText.Text + " " + wachtwoordText.Text);
SW.WriteLine("exit");
string line = null;
do
{
line = SR.ReadLine();
if ((line != null))
{
VerbindingOutput.Text = VerbindingOutput.Text + line + Environment.NewLine;
}
} while (!(line == null));
}