用vbs实现配置静态 IP 地址
程序员文章站
2022-04-10 08:01:09
将计算机的 ip 地址设置为 192.168.1.141,并将 ip 网关设置为 192.168.1.100。...
将计算机的 ip 地址设置为 192.168.1.141,并将 ip 网关设置为 192.168.1.100。
脚本代码
strcomputer = "."
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colnetadapters = objwmiservice.execquery _
("select * from win32_networkadapterconfiguration where ipenabled=true")
stripaddress = array("192.168.1.141")
strsubnetmask = array("255.255.255.0")
strgateway = array("192.168.1.100")
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 not be changed."
end if
next
脚本代码
复制代码 代码如下:
strcomputer = "."
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colnetadapters = objwmiservice.execquery _
("select * from win32_networkadapterconfiguration where ipenabled=true")
stripaddress = array("192.168.1.141")
strsubnetmask = array("255.255.255.0")
strgateway = array("192.168.1.100")
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 not be changed."
end if
next