2012-08-06 62 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 /?」