|
发表于 2019-3-24 12:21
来自手机
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
美好未来686 发表于 2019-3-22 14:14
不行啊!我查过CMD改IP地址,不适合win10
Private Sub GetIPConfig() '获取IP地址/子掩码/网关
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
Cells(1, 1) = "IP address:"
Cells(2, 1) = "Subnet:"
Cells(3, 1) = "Gateway:"
For Each ipconfig In IPConfigSet
If Not IsNull(ipconfig.IPAddress) Then
If Not ipconfig.IPAddress(0) = "0.0.0.0" Then Cells(1, 2) = ipconfig.IPAddress(0)
End If
If Not IsNull(ipconfig.IPSubnet) Then
If Not ipconfig.IPSubnet(0) = "" Then Cells(2, 2) = ipconfig.IPSubnet(0)
End If
If Not IsNull(ipconfig.DefaultIPGateway) Then
If Not ipconfig.DefaultIPGateway(0) = "0.0.0.0" Then Cells(3, 2) = ipconfig.DefaultIPGateway(0)
End If
Next
End Sub
Sub UpdateIPConfig() '设置IP地址/子掩码/网关
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
If Cells(1, 2) <> "" And Cells(2, 2) <> "" And Cells(3, 2) <> "" Then
strIPAddress = Array(Cells(1, 2).Value)
strSubnetMask = Array(Cells(2, 2).Value)
strGateway = Array(Cells(3, 2).Value)
strGatewaymetric = Array(1)
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways( _
strGateway, strGatewaymetric)
Next
End If
End Sub
|
|