在 XP 中通过命令行连接/断开 VPN 客户端

ned*_*edm 22 vpn windows-xp command-line-interface

在 XP Pro 工作站中,有没有办法启动本机 Windows VPN 客户端并从命令行打开/关闭连接,以便可以在批处理文件中编写脚本?

Joh*_*nie 31

是的,如果 VPN 连接被称为“我的 VPN”,则:

rasdial "My VPN"
Run Code Online (Sandbox Code Playgroud)

将拨打连接。如果连接失败,它会将错误级别设置为 RAS 错误代码,这样您的脚本就可以检测到连接失败。如果您需要提供用户名和密码而不是使用保存的凭据,请使用:

rasdial "My VPN" username password
Run Code Online (Sandbox Code Playgroud)

要断开连接,请使用:

rasdial "My VPN" /disconnect
Run Code Online (Sandbox Code Playgroud)

JR

  • +1。这正是我在构建自动化脚本中寻找的内容。比我预期的要容易得多。 (2认同)

EM0*_*EM0 5

在 Windows 7 下工作的替代方案(不确定 XP)是:

rasphone -d "My VPN"
Run Code Online (Sandbox Code Playgroud)

这会打开“拨号”对话框,就像双击连接一样。如果您保存了用户名和密码,它会自动拨号。

rasdial 对我不起作用(在 Windows 7 上):

Verifying username and password...

Remote Access error 691 - The remote connection was denied because the user name
 and password combination you provided is not recognized, or the selected authen
tication protocol is not permitted on the remote access server.
Run Code Online (Sandbox Code Playgroud)

如果您在 Windows 7 下添加空字符串,它可以使用缓存的凭据:rasdial "My VPN" "" ""(这是两对双引号,中间没有任何内容)