2012-08-06 64 views
2

我正在使用Java中的程序(仅适用于Windows),它创建PPPoE连接(它并不那么重要)。重要的是,我需要有些在局域网选项卡中禁用IPv4。通过CMD /注册表禁用IPv4

problem http://img228.imageshack.us/img228/3253/4dcb10eb731a403e9fc785e.png

(其在捷克语)


我需要以某种方式 “取消” 的IPv4协议的ceratin网络适配器。我能够通过CMD和netsh工具设置一些东西,但我无法设法禁用单个适配器的IPv4协议。我知道如何禁用整个计算机的IPv4,但这不适用于我(因为我需要IPv4通信,只是通过不同的渠道)。 我知道如何通过Windows注册表(我发现它在互联网上)“取消”IPv6,但同样不适用于IPv4。

任何帮助将不胜感激。

结果我需要实现(编程)

result http://img35.imageshack.us/img35/8459/bfebacf3b9bb428c84dee44.png

PS:请不要问我为什么做在Java中只有Windows的应用程序...

+0

我知道如何在C++中做到这一点,就觉得满意?我怀疑是否有任何方法可以在Java中完成,但是您可以为您的Java程序可以调用的这个任务创建一个小型C++程序。 – 2012-08-06 20:21:53

+0

那么,我可能会想出一个方法来执行它。我可以通过适配器我想禁用IPv4到你的程序吗? 我真的很高兴为您提供帮助。 在此先感谢 – manWe 2012-08-06 20:44:46

回答

3

见微软的示例代码here

你要替换MS_TCPIP到ms_tcpip6参考,你可能需要做一些试验工作,如何以确定正确的适配器。这种额外的代码片段可能会有帮助,它属于中内环:

 [...] 
     while (hr == S_OK) 
     { 
      LPWSTR lpszPathToken; 
      hr = pncbp->GetPathToken(&lpszPathToken); 
      if (hr != S_OK) fail(hr); 
      wprintf(L"Path token: %s\n", lpszPathToken); 

      // Get owner 

      INetCfgComponent *owner; 
      LPWSTR lpszOwner; 

      hr = pncbp->GetOwner(&owner); 
      if (hr != S_OK) fail(hr); 

      hr = owner->GetId(&lpszOwner); 
      if (hr != S_OK) fail(hr); 

      wprintf(L"Path owner: %s\n", lpszOwner); 
      // Disable this binding. 

      hr = pncbp->Enable(ENABLE); 
      [...] 

希望一个路径令牌或路径老板会给你你需要确定正确的适配器的信息。

+0

我可能会测试它,但我不知道这个程序是否会在没有任何框架等的标准PC上运行(因为它需要一些Windows套件来构建)。但如果没有什么可行的,我不得不尝试这个。 感谢您的帮助! – manWe 2012-08-07 07:22:44

+0

你不需要安装任何额外的库,DDK只暴露Windows内部。 – nothrow 2012-08-07 13:13:06

+0

您需要DDK来编译此代码,但不能运行它。我在没有安装DDK的机器上自己使用它。如果您将Visual C++设置为使用静态运行时库,则不需要分发该静态运行时库。 – 2012-08-08 01:46:25

0

检查这个工具:https://gallery.technet.microsoft.com/Hyper-V-Network-VSP-Bind-cf937850

nvspbind is a tool for modifying network bindings from the command line. It is especially useful in Server Core environments with the Hyper-V role enabled. 

It can be used to set the correct bindings for NICs used in Virtual Networks. 

It can also be used to enable or disable specific bindings on any NIC and to query and change the NIC connection order. 

It utilizes the INetCfg APIs documented on MSDN (http://msdn.microsoft.com/en-us/library/ms805265.aspx). 

Most options are documented in the readme and nvpsbind.txt which download with the install. 

To get help run “nvspbind.exe /?”