如何通过VB编程,读取/修改本机ip地址和子网掩码及网关地址?
内容同上?高分赠送
[解决办法]
strComputer = ". "
Set objWMIService = GetObject( "winmgmts:\\ " & strComputer & "\root\cimv2 ")
Set colNetAdapters = objWMIService.ExecQuery _
( "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE ")
For Each objNetAdapter in colNetAdapters
sip=objNetAdapter.IPAddress
strIPAddress = sip '保持原来的ip,如果需要修改ip为192.168.0.200:strIPAddress = Array( "192.168.0.200 ")
strSubnetMask = Array( "255.255.255.0 ")
strGateway = Array( "192.168.0.254 ") '修改网关为192.168.0.254
strGatewayMetric = Array(1)
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
msgbox "The IP address has been changed. "
Else
msgbox "The IP address could not be changed. "
End If
exit for '只修改第一个网卡的设置
Next
[解决办法]
http://www.vbgood.com/viewthread.php?tid=25879
http://topic.csdn.net/t/20020915/16/1025383.html
[解决办法]
'dwOperStatus As Long操作狀態,以下值之一:
'常量名稱 說明
'-----------------------------------------
MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0 '网絡适配器被禁止,例如:地址沖突
MIB_IF_OPER_STATUS_UNREACHABLE = 1 '沒有連接
MIB_IF_OPER_STATUS_DISCONNECTED = 2 '局域网:電纜未連接;廣域网:無載波信號
MIB_IF_OPER_STATUS_CONNECTING = 3 '廣域网适配器連接中
MIB_IF_OPER_STATUS_CONNECTED = 4 '廣域网适配器連接上遠程對等點
MIB_IF_OPER_STATUS_OPERATIONAL = 5 '局域网适配器默認狀態