【发布时间】:2019-10-20 05:27:08
【问题描述】:
我正在使用带有 DotRas SDK https://archive.codeplex.com/?p=dotras 的 vb.net 我有一个问题,如果我尝试执行该示例,我总是收到错误“不支持转换值 'gre'。”
一定是调用出错
RasDevice.GetDevice
完整的调用是:
Dim entry As RasEntry = RasEntry.CreateVpnEntry(EntryName, IPAddress.Loopback.ToString(), RasVpnStrategy.Default, RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn))
有没有人知道问题可能是什么,或者如何解决?
我使用的是 Windows Server 2016 64 位
谢谢!
编辑:
Public Class MainForm
Public Const EntryName As String = "VPN Connection"
Private connectionHandle As RasHandle
Private Sub CreateEntryButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateEntryButton.Click
' This opens the phonebook so it can be used. Different overloads here will determine where the phonebook is opened/created.
Me.AllUsersPhoneBook.Open()
Dim device = RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn)
Dim entry = RasEntry.CreateVpnEntry(EntryName, IPAddress.Loopback.ToString(), RasVpnStrategy.Default, device)
' Add the new entry to the phone book.
Me.AllUsersPhoneBook.Entries.Add(entry)
End Sub
【问题讨论】:
-
将一行分成两行:
Dim device = RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn)和Dim entry = RasEntry.CreateVpnEntry(EntryName, IPAddress.Loopback.ToString(), RasVpnStrategy.Default, device)。第一行是否执行? (测试你关于那个调用失败的理论。如果它有效,那么它在其他地方。(这只是基本的调试) -
还有一个与
GetDeviceByName一起使用的参数称为exactMatchOnly。在您链接的页面上的示例视频中 @ 2:23false作为参数传递。 -
该视频还显示了
this.rasPhoneBook1.Open()事先调用。它必须是示例中窗体上的控件。请务必包含所有相关代码。 -
您好,我在第一篇文章中添加了整个相关代码(这是存档中的示例代码)。正如你所建议的,我将线路一分为二,但仍然因 Dim device = RasDevice.GetDeviceByName("(PPTP)",RasDeviceType.Vpn) 而失败。我也尝试在 GetDeviceByName 调用中添加“false”,但它没有改变任何东西,错误仍然相同。谢谢您的帮助!
-
我在我的机器上运行了这个例子,它可以工作。它返回“WAN Miniport (PPTP)”连接。也许它在您的系统上不可用。确保它在那里并启用。关注this tutorial