分享一段VBS,可以修改网吧电脑客户机的计算机名称和IP的。
修改网吧电脑IP的同时修改电脑的DNS,网关等信息一起修改了,下面是完整的代码:
'On Error Resume Next Const DNS1="202.99.160.68" Const DNS2="202.99.166.4" Const GateWay="192.168.16.100" Const MASK="255.255.255.0" num=0 num=InPutBox("请输入本机号","输入") If Trim(num) = "" Then MsgBox "您没输入值,退出。" : WScript.quit End If If num=0 or num>255 or num <1 then MsgBox "输入有错误,退出。" : WScript.quit num=Cint(num) IP="192.168.16."&num num=Cstr(num) if num <10 then num="00"&num end if if num <100 and num>9 then num="0"&num end if COMPUTER_NAME="net"&num wscript.echo COMPUTER_NAME &" "& IP dim fso,wshell,ipobj,ComputerObj,Nobj,Adapter,LINK_INDEX,LINK_NAME Set Adapter=GetObject("winmgmts:").InstancesOf("WIN32_NetworkAdapter") For Each link In Adapter If mid(link.NetConnectionID,1,4)="本地连接" And InStr(1,link.name,"TV/Video") =0 Then '这样处理因为有时叫本地连接1.2.3...然后再除掉装摄像头后的虚拟网卡 LINK_NAME=link.NetConnectionID LINK_INDEX=link.index End If Next set wshell=CreateObject("WScript.Shell") Set fso=CreateObject("Scripting.FileSystemObject") Set nobj=GetObject("winmgmts:\\.\root\cimv2") Set ComputerObj=nobj.ExecQuery("select * from Win32_ComputerSystem") Set ipobj=nobj.execQuery("select * from WIN32_NETWORKADAPTERCONFIGURATION where index="&CStr(LINK_INDEX)) for each co in computerobj co.rename COMPUTER_NAME '修改计算机名 next for each IO in ipobj IO.EnableStatic Array(IP),Array(MASK) '修改IP地址 IO.SetGateWays Array(GateWay) '修改默认网关 IO.SetDNSServerSearchOrder Array(DNS1,DNS2) '修改DNS next
代码分析:
本代码运行后需要用户收入本机的机器号,然后修改本地连接里面的相关IP信息和计算机名称完成。
源码相关讨论: