c# - 如何解决 C# 中的 VPN 连接错误
问题描述
我在我的程序中使用了一个 VPN 类。但是当我尝试连接时,会导致以下错误:
系统找不到此连接的电话簿条目
这是连接方法:
public void VPN_Connect(string VPN_Name, string VPN_ID, string VPN_PW)
{
string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Network\Connections\Pbk\rasphone.pbk";
AllUsersPhoneBook = new RasPhoneBook();
AllUsersPhoneBook.Open(path);
if (AllUsersPhoneBook.Entries.Contains(EntryName))
{
AllUsersPhoneBook.Entries[EntryName].PhoneNumber = VPN_Name;
AllUsersPhoneBook.Entries[EntryName].Update();
}
else
{
RasEntry entry = RasEntry.CreateVpnEntry(EntryName, VPN_Name, RasVpnStrategy.Default,
RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn));
entry.EncryptionType = RasEncryptionType.None;
AllUsersPhoneBook.Entries.Add(entry);
}
Dialer = new RasDialer();
Dialer.DialCompleted += new EventHandler<DialCompletedEventArgs>(Dialer_DialCompleted);
this.Dialer.EntryName = EntryName;
this.Dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
try
{
this.Dialer.Credentials = new NetworkCredential(VPN_ID, VPN_PW);
this.handle = this.Dialer.DialAsync();
VPN_Status = (int)status.Defalut;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
我怎么解决这个问题?
我还在使用带有最新更新和 DotRas 最新版本的 Windows 10。
解决方案
推荐阅读
- python - 如何在 python MySQLDB VALUE 子句中插入字符串列表
- linux - 如何在 Gentoo 中列出已安装的屏蔽包?
- php - 自动登录 WKwebview
- mysql - 实际解决方案与我的解决方案有什么区别?
- javascript - Electron构建访问静态图片vue js
- c++ - C++ 无法访问 PEB LDR InLoadOrderModuleList
- python - 如何使用 NumPy 生成具有条件概率的 x 和 y 样本
- django - Django 消息在管理员 model_save() 中不起作用
- appium - 无法使用 pycharm/appium 服务器(1.15.1)为移动应用程序定位元素(id)。但是 Appium Studio 可以找到相同的元素
- ruby-on-rails - 为什么我的创建表单没有工作,甚至没有响应?