用于修改 DNS IP 地址的 VB Shell 脚本

用于修改 DNS IP 地址的 VB Shell 脚本,第1张

概述用于修改 DNS IP 地址的 VB Shell 脚本

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

' This script changes the DNS servers for a network device in windows' to a defined IP or deletes them and makes it the default automatic' Test if in admin mode by detecting 'elevated' in the command line that launched this script' WScript is basically a THIS script objectIf WScript.Arguments.named.Exists("elevated") = False Then	'Launch this script again as administrator	CreateObject _	 ("Shell.Application").ShellExecute _	 	"wscript.exe","""" & WScript.ScriptFullname & """ /elevated","","runas",1	WScript.QuitElse	'Change the working directory from the system32 folder back to the script's folder.	Set oShell = CreateObject("WScript.Shell")	oShell.CurrentDirectory = CreateObject _		("Scripting.fileSystemObject").GetParentFoldername(WScript.ScriptFullname)	'MsgBox "Now running with elevated permissions"End If' define the DNS Primary and secondary server IPs DNSserv = "111.111.111.111,222.222.222.222"' Ask if the DNS servers should be set or removediAction = MsgBox("Would you like to use DNS?",_		vbYesNoCancel+vbQuestion+vbApplicationModal,"DNS Toggle: " & DNSserv)' Cancel was selected - quit this scriptIf vbCancel = iAction Then	WScript.QuitEnd IfstrComputer = "." ' This computer' Get the Script shell and WMI Service objectsSet objWMIService = Getobject("winmgmts:\" & strComputer & "\root\cimv2")Set WshShell = WScript.CreateObject("WScript.Shell")' The registry key that hold the TCP/IP parametersRegkey = "HKEY_LOCAL_MACHINE\SYstem\ControlSet001\services\Tcpip\Parameters\Interfaces\"' Enumerate all of the enabled network devicesSet IPDevSet = objWMIService.Execquery _("Select SettingID from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")DNSservRead = ""For Each IPDev in IPDevSet	' Get the current setting 	DNSservRead = WshShell.RegRead _		( Regkey & IPDev.SettingID & "\nameServer")	'MsgBox "DNS Servers was set to:"  & vbCrLf & DNSservRead,vbOK,"old Status"	' if it's blank and the user chose YES set it to the DNS Server values.	' So we don't overwrite the values that are already set 	If "" = DNSservRead and vbYes = iAction Then 		'Combine regkey,settingID,and nameserver to create the correct registry key path		WshShell.RegWrite Regkey & IPDev.SettingID & "\nameServer",DNSserv,"REG_SZ"			' If the user selected NO to delete the DNS values this script sets 	' and it's not set to those DNS values do not mess with it.	ElseIf DNSservRead = DNSServ and vbNo = iAction Then 		WshShell.RegWrite Regkey & IPDev.SettingID & "\nameServer","REG_SZ"	End If   	' See the new setting	'DNSservRead = WshShell.RegRead( Regkey & IPDev.SettingID & "\nameServer")	'MsgBox "DNS Servers Now set to:"  & vbCrLf & DNSservRead,"New Status"Next'Final messageszTitle = ""szMssg = ""If vbYes = iAction Then 	szMssg = "DNS Servers Now set to use:" & vbCrLf & " " & DNSserv	szTitle = "DNS.com is ON"Else	szMssg = "DNS Servers deleted."& vbCrLf & "Now set to automatic"	szTitle = "DNS.com is OFF"End IfMsgBox szMssg,vbinformation,szTitle

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的用于修改 DNS IP 地址的 VB Shell 脚本全部内容,希望文章能够帮你解决用于修改 DNS IP 地址的 VB Shell 脚本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1274823.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存