public void IpSecConnectionRemove(string ipSecConnectionName) { if (ipSecConnectionName == null) { throw new ArgumentNullException(nameof(ipSecConnectionName)); } if (ipSecConnectionName.Length == 0) { throw new ArgumentException($"nameof(ipSecConnectionName) is empty string"); } using (var rasPhoneBook = new RasPhoneBook()) { rasPhoneBook.Open(IpSecClient._phoneBookPath); var ipSecRasEntry = IpSecClient.RasEntryFindByName(rasPhoneBook, ipSecConnectionName); if (ipSecRasEntry.Remove()) { Console.WriteLine($"VPN connection {ipSecConnectionName} removed successfully."); } else { throw new Exception("RasEntry.Remove() failed."); } } }
private RasEntry IpSecRasEntryGet(string ipSecConnectionName) { RasEntry ipSecRasEntry = null; using (var rasPhoneBook = new RasPhoneBook()) { rasPhoneBook.Open(IpSecClient._phoneBookPath); ipSecRasEntry = IpSecClient.RasEntryFindByName(rasPhoneBook, ipSecConnectionName); } return(ipSecRasEntry); }