我希望创建一系列批处理文件,在启动 VPN(如果尚未运行)之前检查特定 VPN 的状态,最后启动特定应用程序。
我有一个有效的示例,但我正在尝试对其进行修改,以作为学习练习和实际扩展。
我目前正在使用 ipconfig 和管道来 find/i 并查找 VPN 名称,强制断开连接,然后重新连接。
我也想做同样的事情,但如果 VPN 已启动,则跳过断开连接。
工作示例:
@echo OFF
::Check to see if the VPN is already connected and disconnect it
echo Checking for VPN connection...
@ipconfig|find/i "myVPN" && rasdial myVPN /disconnect
echo.
echo.
::Connect to the VPN server
@rasdial.exe myVPN "username" "password"
echo.
echo.
Run Code Online (Sandbox Code Playgroud)
正如我所说,这可行,但 VPN 的强制断开会扰乱可能通过 VPN 运行的其他一些服务,正如您可以想象的那样。
这就是我一直在玩的东西,但我似乎被困住了,一无所获,非常感谢您的建议!
进步:
@echo OFF
::Check to see if the VPN is already connected and disconnect it
echo Checking for VPN connection... …Run Code Online (Sandbox Code Playgroud)