核心代碼一:
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 not be changed." End If Next
記得把參數(shù)改成自己想要的。
代碼二:
將計算機(jī)的 IP 地址設(shè)置為 192.168.1.111,并將 IP 網(wǎng)關(guān)設(shè)置為 192.168.1.1。
strComputer = "." Set objWMIService = GetObject("winmgmts:\" strComputer " ootcimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("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 not be changed." End If Next
原文:http://demon.tw/programming/vbs-modify-ip-dns-setting.html
標(biāo)簽:梅州 河南 伊春 四平 武威 咸陽 阜陽 牡丹江
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《用VBS設(shè)置靜態(tài)IP和DNS服務(wù)器地址的代碼》,本文關(guān)鍵詞 用,VBS,設(shè)置,靜態(tài),和,DNS,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。下一篇:獲取屏幕分辨率的VBS代碼