我有一个小的VB.NET程序,它创建了一个VPN连接。 这工作直到(包括)Windows 10 Update 1709。 但自从更新1803以来,我总是得到一个例外:
DotRas.RasException:检测到错误的结构大小。 at DotRas.Internal.ThrowHelper.ThrowRasException(Int32 errorCode) 在DotRas.Internal.RasHelper.GetEntryProperties(RasPhoneBook phoneBook,String entryName) 在DotRas.RasEntryCollection.Load() 在DotRas.RasPhoneBook.Open(String phoneBookPath)
遵循我的Code Sub(直到1709年)
Private Sub CreateVPN(VpnName As String, Destination As String, bAllUsers As Boolean)
Dim PresharedKey As String = "XXXXXXXXXXX"
Try
Dim PhoneBook As New RasPhoneBook
Dim sUsedPhoneBook As String = sPhoneBook
If bAllUsers Then sUsedPhoneBook = sAllUserPhoneBook
PhoneBook.Open(sUsedPhoneBook)
'First remove existing VPN with same name, if exist!
Try
PhoneBook.Entries.Remove(VpnName)
Catch ex As Exception
End Try
Dim VpnEntry As RasEntry = RasEntry.CreateVpnEntry(VpnName, Destination, DotRas.RasVpnStrategy.L2tpOnly, DotRas.RasDevice.Create(VpnName, DotRas.RasDeviceType.Vpn))
VpnEntry.Options.UsePreSharedKey = True
VpnEntry.Options.IPHeaderCompression = True
VpnEntry.Options.SoftwareCompression = True
VpnEntry.Options.NetworkLogOn = True
VpnEntry.NetworkProtocols.IPv6 = False
VpnEntry.Options.RequireEap = False
VpnEntry.Options.RequirePap = True
VpnEntry.Options.RequireChap = True
VpnEntry.Options.RequireMSChap2 = True
VpnEntry.Options.RequireEncryptedPassword = False
VpnEntry.Options.UseLogOnCredentials = False
VpnEntry.Options.CacheCredentials = False
VpnEntry.DnsSuffix = "YYYYYYY.local"
VpnEntry.Options.UseDnsSuffixForRegistration = True
' *********** THE FOLLOWING LINE WILL CRASH ON WINDOWS 10 1803 **********
PhoneBook.Entries.Add(VpnEntry)
VpnEntry.UpdateCredentials(RasPreSharedKey.Client, PresharedKey)
If txt_Username.Text <> "" AndAlso txt_Password.Text <> "" Then
VpnEntry.UpdateCredentials(New Net.NetworkCredential(txt_Username.Text, txt_Password.Text), False)
VpnEntry.Options.CacheCredentials = True
VpnEntry.Update()
End If
PhoneBook.Dispose()
txt_Status.Text = VpnName & " successful added."
txt_Status.ForeColor = Color.DarkGreen
Catch ex As Exception
Console.WriteLine("Error while adding " & VpnName & "." & Environment.NewLine & ex.ToString)
Finally
End Try
End Sub
有人能帮助我吗? 我没有找到更新的DotRAS.dll。 最好的是没有外部DLL的工作示例。
提前谢谢。