您好,登錄后才能下訂單哦!
這篇文章給大家介紹VBS中怎么設置靜態IP和DNS服務器地址,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
核心代碼一:
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
記得把參數改成自己想要的。
代碼二:
將計算機的 IP 地址設置為 192.168.1.111,并將 IP 網關設置為 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
關于VBS中怎么設置靜態IP和DNS服務器地址就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。