I tried to open a OpenVPN connection using a small c# program.
Below is the code I used.
static void Main(string[] args)
{
Process rs = new Process();
var netCredential = new System.Net.NetworkCredential("User", "PWD", "Domain");
System.Environment.CurrentDirectory = ".\\";
ProcessStartInfo info = new ProcessStartInfo
{
FileName = "c:\\programme\\openvpn\\bin\\openvpn.exe",
Arguments = "--config c:\\programme\\openvpn\\config\\NAS-Name.ovpn",
UserName = netCredential.UserName,
Domain = netCredential.Domain,
Password = netCredential.SecurePassword,
UseShellExecute = false,
//RedirectStandardError = true,
//RedirectStandardOutput = true,
//CreateNoWindow = true,
WorkingDirectory = Path.GetDirectoryName("c:\\programme\\openvpn\\bin\\openvpn.exe")
};
var p = Process.Start(info);
}
This code does work, but only on the computer were I compiled it.
On our server (Win server 2019) I get the error:
Unhandled Exception: System.ComponentModel.Win32Exception:System cant find file at System.Diagnostics.ProcessWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at ConnectOpenVPN.Program.Main(String[] args) in C:\User\path\to\Program.cs:Zeile 43
I don´t understand where the last line of the error message comes from.

Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)). And thenPath.Combineto add the openvpn part.if (File.Exists(pathToFile)) ...)