Core code One:
strIPAddress = Array ("192.168.0.148")
Strsubnetmask = Array ("255.255.255.0")
Strgateway = Array ("192.168.0.1 ")
strgatewaymetric = Array (1)
arrdnsservers = Array (" 192.168.0.1 "," 192.168.0.2 ")
StrComputer =". "
Set objWMIService = GetObject ("winmgmts:" _
& "{impersonationlevel=impersonate}!\\" & strComputer & "\ root\cimv2 ")
Set colnetadapters = objWMIService.ExecQuery _
(" Select * FROM Win32_NetworkAdapterConfiguration where Ipenabled=true ") for each
objnetadapter in colnetadapters
errenable = objnetadapter.enablestatic ( strIPAddress, strsubnetmask)
errgateways = Objnetadapter.setgateways (Strgateway, Strgatewaymetric)
Errdns = Objnetadapter.setdnsserversearchorder (arrdnsservers)
If errenable = 0 Then
WScript.Echo "The IP Address has been changed. "
Else
WScript.Echo "The IP address could is not changed."
End If
Remember to change the parameters to what you want.
Code two:
Set the computer's IP address to 192.168.1.111, and set the IP gateway to 192.168.1.1.
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:\" & StrComputer & "Ootcimv2")
set colnetadapters = Objwmiservice.ex Ecquery _
("select * from Win32_NetworkAdapterConfiguration where ipenabled=true")
stripaddress = Array (" 192.168.1.111 ")
Strsubnetmask = Array (" 255.255.255.0 ")
Strgateway = Array (" 192.168.1.1 ")
Strgatewaymetric = Array (1) for each
objnetadapter in colnetadapters
errenable = objnetadapter.enablestatic ( strIPAddress, strsubnetmask)
errgateways = Objnetadapter.setgateways (Strgateway, strgatewaymetric)
If errenable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could is not changed."
End If
Next
Original: http://demon.tw/programming/vbs-modify-ip-dns-setting.html