Get the result after connecting to VPN
I can connect to an existing VPN created with the following code.
string args = string.Format("{0} {1} {2}", connVpnName, connUserName, connPassWord);
var proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = "C:\\WINDOWS\\system32\\rasdial.exe",
Arguments = args,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
string output = "";
while (!proc.StandardOutput.EndOfStream)
{
output += proc.StandardOutput.ReadLine();
txtOutput.Text += proc.StandardOutput.ReadLine();
}
I need to know if the connection was successful, incorrect credentials, where used, VPN does not activate or if ip is not connected to the network.
My first idea was to get output from the command line and look for keywords such as "connected". The problem with this method is that my users are using multiple languages ββand the keywords will be different.
Can I use another method for this?
+3
source to share
2 answers
I found the answer:
proc.Start();
//het resultaat bekijken
proc.WaitForExit();
switch (proc.ExitCode)
{
case 0: //connection succeeded
MessageBox.Show("Je bent geconnecteerd met de VPN");
isConnectedVPN = true;
btnConnectToVPN.Text = "Stop VPN";
break;
case 691: //wrong credentials
MessageBox.Show("De username en/of het wachtwoord kloppen niet.");
break;
case 623: // The VPN doesn't excist
MessageBox.Show("Deze VPN staat niet tussen de bestaande VPN's.");
break;
case 868: //the IP or domainname can't be found
MessageBox.Show("Het ip-adres of de domeinnaam kan niet gevonden worden");
break;
default: //other faults
MessageBox.Show("fout " + proc.ExitCode.ToString());
break;
}
0
source to share