java - 如何使用 Runtime.exec() 发送的“Get-VpnConnection”PowerShell 命令获取 VPN 的 ConnectionStatus?
问题描述
在我的 Java 代码中,我想确保在通过 PowerShell 命令添加 VPN 并调用 rasdial 连接到它之后,它实际上是连接的。
Runtime rt = Runtime.getRuntime();
try {
String command = "powershell.exe Add-VpnConnection -Name \"ProxyConnector\" -ServerAddress \""+serverAddress+":"+port+"\" ";
rt.exec(command);
String command2 = "rasdial.exe ProxyConnector "+username+" "+password;
rt.exec(command2);
} catch (IOException e) {
e.printStackTrace();
}
我知道该命令Get-VpnConnection -Name %VpnName%
提供了有关 VPN 的所有信息(如果存在),但我如何只取值 ConnectionStatus?它对我的目的真的可靠吗?
解决方案
推荐阅读
- mysql - MySQL如何重复查询列中的每个值
- telegram - 机器人给出模板答案
- azure-cosmosdb - Cosmos DB (Mongo DB API) 跨分区查询性能不佳
- python-3.x - Python DLL 导入错误,找不到模块
- haskell - 用无点样式的Haskell中的字符串替换字符串中的字符
- node.js - 使用 Express 部署到 Heroku,React 应用程序保持空白
- django - 从 django 2.7 中基于 AbstractUser 的模型继承
- php - 从 html (raspberry pi) 调用时,php 脚本无法正常工作
- javascript - 尝试使用来自 coco-ssd 的数据来绘制边界框
- flutter - Flutter:如何在后台处理程序上区分应用程序被终止和应用程序运行状态