http://www.wangchao.net.cn/bbsdetail_35583.htmlhttp://www.google.cn/search?hl=zh-CN&source=hp&q=wmi+dns+ 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")fso的那段儿可以去掉了
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() outFile.WriteLine(objNIC.Description & " ") outFile.WriteLine("Change DNS ok") End If Next outFile.WriteLine("Change over") 我一直不明白为什么你们不肯好好看我给的链接呢.....人家都把方案摆好了,你仔细分析一下就知道了我现在做的就是那个pdf上写的....你自己好好看看吧
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")fso的那段儿可以去掉了
"我用VB修改了IP及DNS,现在我想求一段VB只恢复DNS自动获得的代码,而IP不动它"
就是说:我用VB代码修改了IP地址及DNS服务地址为固定的,现在我想仍用VB代码将固定的DNS服务地址恢复到自动获得状态,而IP地址仍为固定的.请指教,谢
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()
outFile.WriteLine(objNIC.Description & " ")
outFile.WriteLine("Change DNS ok")
End If
Next
outFile.WriteLine("Change over")
我一直不明白为什么你们不肯好好看我给的链接呢.....人家都把方案摆好了,你仔细分析一下就知道了我现在做的就是那个pdf上写的....你自己好好看看吧