Kindly be advised we cannot cancel subscriptions or issue refunds on the forum.
You may cancel your Bitdefender subscription from Bitdefender Central or by contacting Customer Support at: https://www.bitdefender.com/consumer/support/help/

Thank you for your understanding.

How to start VPN using the pre-saved VPN credentials?

Options

I have set up a VPN connection in Windows 7, called "My VPN", which has saved credentials. So, when I start the VPN manually in Windows, it connects right away without asking the user for their login or password.

I now want to start the same VPN connection from code, using the saved credentials, but I haven't found a way to start it without having to provide the credentials in code, which I'd rather not do for security reasons. For example, this works ok, as long as I provide the login & password in the argument string:

cmd.StartInfo.FileName = "rasdial.exe";
cmd.StartInfo.Arguments = "\"My VPN\" mylogin mypassword";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.ErrorDialog = true;
cmd.StartInfo.RedirectStandardError = true;
cmd.Start();

When I leave out the credentials from the argument string, it refuses to connect, even though that connection has them saved. Is there a way to force it from code to use the saved credentials?

(Ed: What I used to do in XP is create a shortcut of the VPN item under Network Connections, then I could simply call eg. "Shortcut to MyVPN.lnk" directly, which would do the trick. Not sure what the Windows 7 equivalent is of that, if possible.)

Ok found out how to create a shortcut to the VPN, so I have a .lnk file now. When I double-click the shortcut, the VPN connects perfectly. Also, I can start it from the command line using start "" "C:\...\MyVPN.lnk" - that works too.

However, I can't reproduce that from code. I have tried:

cmd.StartInfo.FileName = "start \"\" \"C:\...\MyVPN.lnk\"";
cmd.StartInfo.Arguments = "";

and

cmd.StartInfo.FileName = "start";
cmd.StartInfo.Arguments = "\"\" \"C:\...\MyVPN.lnk\"";

Which throw Win32Exception "The system cannot find the file specified." Variations using cmd.exe also fail... I've run out of ideas at the moment.