So, my work uses a VPN for me to be able to remotely log in whenever I need to. However the configuration changes frequently. So, instead of downloading a file every day and overwriting the existing configuration file manually I wanted it to be automated.
So far, here's what I have:
using System;
using System.Linq;
using System.IO;
using System.Net;
using System.Windows.Forms;
using System.Diagnostics;
namespace Config_Updater
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Uri uri = new Uri("https://myupdatedconfigfile.com");
string filename = @"C:\Program Files\OpenVPN\config";
{
begin:
Process[] pname = Process.GetProcessesByName("OpenVPN");
if (pname.Length == 1)
{
//string processName = "OpenVPN";
foreach (Process proc in Process.GetProcessesByName("OpenVPN"))
proc.Kill();
goto begin;
}
try
{
if (File.Exists(filename))
{
File.Delete(filename);
}
else
{
WebClient wc = new WebClient();
wc.DownloadFile(uri, filename);
}
finally
{
Application.Exit();
}
}
}
}
}
So, I want the program to accomplish several things.
- If the OpenVPN process is already running I want it to close it.
- I want it to identify and delete the old config file to ensure it is completely removed.
- Download the most current Config file for OpenVPN and then end application.
However, when I debug this program I get a WebClient was unable to initialize type error. Am I missing a step completely? Did I not include a specific "using System"?
Any and all help you can provide me with would be very much appreciated.

New Topic/Question
Reply



MultiQuote





|