Attempting to set L2tp Only VPN properties in C#

2019-07-26 23:06发布

问题:

I am attempting to create a console app to create a VPN connection for my company. I am able to create the VPN connection but unable to set a few of the properties. I want Unencrypted password (PAP) to be true and CHAP and CHAP2 to be false. But, the opposite is happening to those settings. I am using DotRas tools. What am i doing wrong or missing?

string VpnName = "Test VPN";
            string Destination = "127.0.0.1";
            string PresharedKey = "testkey";
            RasPhoneBook PhoneBook = new RasPhoneBook();
            PhoneBook.Open();

            RasEntry VpnEntry = RasEntry.CreateVpnEntry(VpnName, Destination, DotRas.RasVpnStrategy.L2tpOnly, DotRas.RasDevice.Create(VpnName, DotRas.RasDeviceType.Vpn));
            VpnEntry.Options.UsePreSharedKey = true;
            VpnEntry.Options.UseLogOnCredentials = false;
            VpnEntry.Options.RequirePap = true;
            VpnEntry.Options.RequireMSChap = false;
            VpnEntry.Options.RequireMSChap2 = false;
            PhoneBook.Entries.Add(VpnEntry);
            VpnEntry.UpdateCredentials(RasPreSharedKey.Client, PresharedKey);
            Console.WriteLine("VPN connection created successfully");

回答1:

You can change the three security checkboxes using a combination of options.

VpnEntry.Options.RequireEncryptedPassword = false;
VpnEntry.Options.RequirePap = true;
VpnEntry.Options.RequireChap = false;
VpnEntry.Options.RequireMSChap = false;
VpnEntry.Options.RequireMSChap2 = false;

Those options will have PAP checked, CHAP unchecked, and MS-CHAP v2 unchecked.



标签: c# vpn dotras