如何使用 rasphone.exe 获得 *** 连接而不总是提示输入密码
Posted
技术标签:
【中文标题】如何使用 rasphone.exe 获得 *** 连接而不总是提示输入密码【英文标题】:How to use rasphone.exe to get *** connection without always prompting for password 【发布时间】:2019-07-25 15:57:16 【问题描述】:我有一个使用 rasphone.exe 接口连接 Windows ***(不是 Open***)的应用程序。我可以成功建立连接,但每次都提示输入密码。有没有办法让界面记住密码,以便如果连接丢失,可以通过编程自动重新建立连接?作为一个注释,当我启动 rasphone.exe 的进程时,当我尝试向它传递多个参数时,我遇到了异常。我唯一可以成功传递的参数是条目名称,我无法添加 -d、-h 或 -f 之类的参数。
这是我的代码:
Imports System.Linq
Imports System.Net.NetworkInformation
Public Class cls***
Public Delegate Sub delPing()
Public Delegate Sub delConnect()
Public Delegate Sub delIdle()
Public Delegate Sub delDisconnect()
Public Delegate Sub delStatus(blnConnected As Boolean)
Public Event Ping As delPing
Public Event Con As delConnect
Public Event Discon As delDisconnect
Public Event Idle As delIdle
Public Event StatusChanged As delStatus
Public strRASPhone As String = "C:\WINDOWS\system32\rasphone.exe"
Public strIPAddress As String = ""
Public str***Con As String = ""
Public blnConnected As Boolean = False
Dim file As String = "C : \Users\Tom\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk"
Protected Sub OnStatusChanged(blnConnected As Boolean)
RaiseEvent StatusChanged(blnConnected)
End Sub
Protected Sub OnDisconnect()
RaiseEvent Discon()
End Sub
Protected Sub OnPing()
RaiseEvent Ping()
End Sub
Protected Sub OnIdle()
RaiseEvent Idle()
End Sub
Protected Sub OnConnect()
RaiseEvent Con()
End Sub
Public ReadOnly Property Connected() As Boolean
Get
Return blnConnected
End Get
End Property
Public Property ConName() As String
Get
Return str***Con
End Get
Set(strValue As String)
str***Con = strValue
End Set
End Property
Public Function Test() As Boolean
Dim blnSucceed As Boolean = False
OnPing()
Dim p As New Ping()
If p.Send(strIPAddress).Status = IPStatus.Success Then
blnSucceed = True
Else
blnSucceed = False
End If
p = Nothing
If blnSucceed <> blnConnected Then
blnConnected = blnSucceed
OnStatusChanged(blnConnected)
End If
OnIdle()
Return blnSucceed
End Function
Public Function Connect() As Boolean
Dim blnSucceed As Boolean = False
Dim optionstr As String = "-f " & file & " -d "
OnConnect()
'MessageBox.Show("str***Con = " )
'Process.Start(strRASPhone, Convert.ToString(" -f ") & file & Convert.ToString(" -d ") _
' & str***Con)
optionstr = ""
Dim wait As Boolean = True
ProcessExec(strRASPhone, optionstr & str***Con, wait)
Application.DoEvents()
System.Threading.Thread.Sleep(5000)
Application.DoEvents()
blnSucceed = True
OnIdle()
Return blnSucceed
End Function
Public Function Disconnect() As Boolean
Dim blnSucceed As Boolean = False
Dim optionstr As String = "-h "
OnDisconnect()
optionstr = ""
Dim wait As Boolean = True
ProcessExec(strRASPhone, optionstr & str***Con, wait)
Application.DoEvents()
System.Threading.Thread.Sleep(8000)
Application.DoEvents()
blnSucceed = True
OnIdle()
Return blnSucceed
End Function
Public Function CheckConnection() As Boolean
Dim ni*** As NetworkInterface() =
NetworkInterface.GetAllNetworkInterfaces
Dim blnExist As Boolean =
ni***.AsEnumerable().Any(Function(x) x.Name = ConName)
If blnExist Then
'MessageBox.Show("*** Exists")
Else
' MessageBox.Show("*** Does Not Exist")
End If
Return blnExist
End Function
Public Sub ProcessExec(processarg As String, param As String, wait As Boolean)
' Start the child process.
Dim p As New ProcessStartInfo
' Redirect the output stream of the child process.
p.FileName = processarg
p.Arguments = param
p.UseShellExecute = True
p.WindowStyle = ProcessWindowStyle.Normal
Dim proc As Process = Process.Start(p)
' Do Not wait for the child process to exit before
' reading to the end of its redirected stream.
If wait = True Then
proc.WaitForExit()
End If
End Sub
End Class
【问题讨论】:
【参考方案1】:我知道一年多以前有人问过这个问题。
我想所描述的问题不是由 vb 代码引起的。问题可能是由文件rasphone.pbk
引起的。它一般包含在%APPDATA%\Microsoft\Network\Connections\Pbk
中。可以使用文本编辑器读取此文件。在[YOUR***NAME]
之后存在一个选项PreviewUserPw
。 1
值会在拨入前生成提示。
将这一行改为
PreviewUserPw=0
会有帮助。
【讨论】:
以上是关于如何使用 rasphone.exe 获得 *** 连接而不总是提示输入密码的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 XML 获得负半径 Android Round Corner