以下的VB Script代码利用WMI修改本机的Gateway,DNS设置(将下面的代码存成 .VBS文件直接双击运行即可).
Const STR_NEWDNS1 = "192.168.0.1"
Const STR_NEWDNS2 = "192.168.0.43"
Const STR_GATEWAY = "192.168.0.1"
Set fs = CreateObject("Scripting.FileSystemObject")
Set outFile = fs.CreateTextFile("NetworkAdapterConfiguration.txt", True)
strWinMgmt = "winmgmts:{impersonationLevel=impersonate}"
Set objNICs = GetObject( strWinMgmt ).InstancesOf( "Win32_NetworkAdapterConfiguration" )
outFile.WriteLine("Begin to change DNS...")
For Each objNIC In objNICs
If objNIC.IPEnabled Then
objNIC.SetDNSServerSearchOrder Array(STR_NEWDNS1,STR_NEWDNS2)
outFile.WriteLine(objNIC.Description & " ")
outFile.WriteLine("Change DNS ok")
objNIC.SetGateways Array(STR_GATEWAY)
outFile.WriteLine("Change gateway ok")
End If
Next
outFile.WriteLine("Change over")
本文地址:http://com.8s8s.com/it/it28844.htm