日期:2014-05-20  浏览次数:20678 次

求高手帮忙啊 小弟非常感谢
我想写段java代码 关闭所有的网络连接 可是网上说

Runtime.getRuntime().exec("netsh interface set interface \"本地连接\" DISABLED");

行。

可是我eclipse跑起来 但禁止不了,求高手帮忙。

我用的是XP系统

------解决方案--------------------
估计参数出现错误了吧,把Process的getErrorStream()拿出来,读取打印出来看看信息是啥。
------解决方案--------------------
:停止服务
@echo on
net stop vmnetdhcp
net stop "VMware NAT Service"
:禁用网络连接
netsh interface set interface name="VMware Network Adapter VMnet1" admin=DISABLED
netsh interface set interface name="VMware Network Adapter VMnet8" admin=DISABLED
:强杀进程
taskkill /F /im vmware-tray.exe
:暂停
pause

供你参考
------解决方案--------------------
Process p = Runtime.getRuntime().exec("netsh interface set interface \"本地连接\" \"DISABLED\"");
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
试试
------解决方案--------------------
探讨
没有指定一个或多个关键性参数
此命令提供的语法不正确。请查看帮助以获取正确的语法信息。

用法 set interface [name = ] IfName
[ [admin = ] ENABLED|DISABLED
[connect = ] CONNECTED|DISCONNECTED
[newname = ] NewName ]

设置接口……

------解决方案--------------------
我是Win7。

很不幸,WinXP似乎是不行的,因为netsh命令无法禁用“专用”接口,而本地连接属于“专用”接口。

只能通过其它命令行工具来实现,比如:DevCon 啥的。

另一种方案是用高版本操作系统的ifmon.dll替换你本机的ifmon.dll。


详细介绍请参见:
http://hi.baidu.com/newuserid/blog/item/752b65fdb3c8361208244dc0.html