發現了兩個方法來啓用或禁用從VBA即改變網絡適配器連接:
「調整這些根據您的需要,即更改適配器名稱,改變啓用或禁用參數,改變路徑,更改文件名等。 VBS方法很長,但提供了更多的控制。蝙蝠的方法是短暫但IMO限於
1使用VBS Source link:
'file name: asdf.vbs
'Get and disable all physical wired adapters (AdapterTypeID=0) (Ethernet 802.3)
'Wscript.Echo "test"
Set wmi = GetObject("winmgmts:root\CIMV2")
Set adapters = wmi.ExecQuery("Select * from Win32_NetworkAdapter where _
AdapterTypeId=0 AND NetConnectionID IS NOT NULL",,48)
For Each adapter in adapters
With adapter
WScript.Echo "available: " & .Availability & " enabled: " & .NetEnabled & " netconStatus: " & .NetConnectionStatus & " status: " & .Status & " netconnID: " & .NetConnectionID & " adType: " & .AdapterType
'adapter.disable()
'adapter.enable()
End With
Next
' Get and disable all physical wireless adapters (AdapterTypeID=9) (wireless)
2使用球棒Ref link1和Ref link2:
'file name: switch_lan6.bat
@echo off
start /MIN cmd.exe /c "netsh interface set interface name="Local Area Connection 6" admin=disabled"
運行這些內部Excel VBA中:
Shell "wscript ""C:\Users\USER\Desktop\asdf.vbs""", vbNormalFocus
或
Call Shell(ThisWorkbook.Path & "\switch_lan6.bat", 0)
來源
2014-11-03 18:19:25
ZAT
AFAIK,使用本機VBA代碼,你不能。也許使用C++,你可以爲VBA創建一個庫,然後你可以。 – 2014-10-30 09:01:45
感謝這個,不知道我是否可以儘量爲VBA創建一個庫(我不是開發者),但我會知道從哪裏開始尋找......再次感謝@SiddharthRout – Arthur 2014-10-31 08:16:26
如果這真的很重要,然後在像freelancer.com/elance.com/odesk.com這樣的網站發佈一個項目。那裏有很多C++大師。你實際上可能會找到某人爲你寫這個庫:) – 2014-10-31 08:18:33