CMD和vbs修改 IP地址及DNS的实现代码


修改IP

cmd /c netsh interface ip set address name=" 本地连接" source=static addr=211.82.56.253 mask=255.255.255.0 gateway=211.82.56.1 gwmetric=1

修改DNS
cmd /c netsh interface ip set dns name="本地连接" source=static addr=202.99.192.66


配置或更新IP地址:
wmic nicconfig where index=0 call enablestatic("192.168.1.5"), ("255.255.255.0") ;index=0说明是配置网络接口1。


配置网关(默认路由):
wmic nicconfig where index=0 call setgateways("192.168.1.1"),(1)


vbs

Const T_GATEWAY = "211.82.56.1" '网关
Const T_NEWDNS1 = "202.99.192.66" 'DNS1
Const T_NEWDNS2 = "60.221.248.43" 'DNS2
strWinMgmt="winmgmts:{impersonationLevel=impersonate}"
Set NICS = GetObject( strWinMgmt ).InstancesOf("Win32_NetworkAdapterConfiguration")
For Each NIC In NICS
If NIC.IPEnabled Then
NIC.SetDNSServerSearchOrder Array(T_NEWDNS1,T_NEWDNS2)
NIC.SetGateways Array(T_GATEWAY)
End If
Next

vbScript on error resume next容错使用心得
vbscript中,错误处理使用onerrorresumenext来完成,如果在你的代码里加入这一句,在这句之后的其他代码如果出现错误,系统将忽略这些错误继续运行后面

vbscript include的办法实现代码第1/2页
任何真正实用的工程开发都必然是多文件的。但是VBScript创建多文件工程要麻烦一点,它对多文件工程,代码复用的支持并不是太好。在C/C++工程里,我

vbscript 读取xml格式的配置文件
ClassclsGetProfile'ル?トドキュメントPrivaterootDoc'xmlファイル名とセクション名をセットする'引数:「1」ファイル名NOTNULL'????:なしPublicSubsetProfile(strFileName