'Problem with process start (close instantly after start)

Okay, so i coded a small app that starts a process and then it opens openvpn. So the first 5-6 times it worked it actually starts the console and connects etc.

Now i only added some more things in the form (didn't touch the process code) now when i click on my connect button all it does is, it opens and immediatly close so basically its not working anymore.

I have been thinking for hours and trying to solve this issue but nothing helps, and everything was working for the first 5-6 times i tested it.

this is my code :

  private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
            {
                MessageBox.Show("Please select a server");
            }

            else if (comboBox1.Text == "server")
            {
            button1.Enabled = false;
            string ServerFileContents = richTextBox1.Text;
            File.WriteAllText("server.ovpn", ServerFileContents);
            string args = "--config server.ovpn";
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            //startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName = Application.StartupPath + @"\bin\openvpn.exe";
            startInfo.Arguments = args;
            startInfo.Verb = "runas";
            process.StartInfo = startInfo;
            process.Start();
            button2.Enabled=true;
            button1.Text = "Connected";
            }   
        }

I have added "requireadministrator" aswell to check if it will work then. I have added some threading sleep to see if it will work but nothing helps.

What am i doing wrong here?

Thanks in advance!

UPDATE : added a console log but its empty so why would it not even open openvpn.exe even it worked for the first 5 times? Also i have removed the requireadministrator to see if the exe is opening and it does open. but i dont know why close instantly.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source