1 頁 (共 1 頁)

使用Script設定ip相關設定

文章發表於 : 2012年 1月 10日, 13:26
kaku
設定DNS
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
arrPrimaryServer = array("10.1.1.214")
strDNSDomain = "citfund.com.tw"
objNetCard.SetDNSServerSearchOrder(arrPrimaryServer)
objNetCard.SetDNSDomain strDNSDomain
Next

設定Default Gateway
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
arrGateway = array("10.1.1.254")
objNetCard.SetGateways(arrGateway)
Next

設定IP Address
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
arrIPAddress = array("10.1.1.147")
arrSubnetMask = array("255.255.255.0")
objNetCard.EnableStatic arrIPAddress, arrSubnetMask
Next

設定Wins
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
strPrimaryServer = "10.1.1.214"
strSecondaryServer = ""
objNetCard.SetWINSServer strPrimaryServer, strSecondaryServer
Next