CSDN博客

img slimak

利用WMI修改本机Gateway,DNS

发表于2004/5/7 22:11:00  889人阅读

以下的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")

阅读全文
0 0

相关文章推荐

img
取 消
img