本文主要是介绍利用WMI修改本机Gateway,DNS,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以下的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")
这篇关于利用WMI修改本机Gateway,DNS的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!