自带的关于网络的命令行工具很多,比如大家熟悉的ping,tracert,ipconfig,telnet,ftp,tftp,netstat,还有不太熟悉的nbtstat,pathping,nslookup,finger,route,netsh......
这些命令又可分成三类:网络检测(如ping)、网络连接(如telnet)和网络配置(如netsh)。前面两种相对简单,本文只介绍两个网络配置工具。
Windows脚本很多事用脚本来做是很简洁的。下面给出几个常用脚本的echo版。
1、显示系统版本
@echo for each ps in getobject _ >ps.vbs
@echo ("winmgmts://./root/cimv2:win32_operatingsystem").instances_ >>ps.vbs
@echo wscript.echo ps.caption^&" "^&ps.version:next >>ps.vbs
cscript //nologo ps.vbs & del ps.vbs
2、列举进程
@echo for each ps in getobject _ >ps.vbs
@echo ("winmgmts://./root/cimv2:win32_process").instances_ >>ps.vbs
@echo wscript.echo ps.handle^&vbtab^&ps.name^&vbtab^&ps.executablepath:next >>ps.vbs
cscript //nologo ps.vbs & del ps.vbs
3、终止进程
@echo for each ps in getobject _ >pk.vbs
@echo ("winmgmts://./root/cimv2:win32_process").instances_ >>pk.vbs
@echo if ps.handle=wscript.arguments(0) then wscript.echo ps.terminate:end if:next >>pk.vbs
要终止PID为123的进程,使用如下语法:
cscript pk.vbs 123
如果显示一个0,表示终止成功。
然后:
del pk.vbs
4、重启系统
@echo for each os in getobject _ >rb.vbs
@echo ("winmgmts:{(shutdown)}!//./root/cimv2:win32_operatingsystem").instances_ >>rb.vbs
@echo os.win32shutdown(2):next >>rb.vbs & cscript //nologo rb.vbs & del rb.vbs
5、列举自启动的服务
@echo for each sc in getobject("winmgmts://./root/cimv2:win32_service").instances_ >sc.vbs
@echo if sc.startmode="Auto" then wscript.echo sc.name^&" - "^&sc.pathname >>sc.vbs
@echo next >>sc.vbs & cscript //nologo sc.vbs & del sc.vbs
6、列举正在运行的服务
@echo for each sc in getobject("winmgmts://./root/cimv2:win32_service").instances_ >sc.vbs
@echo if sc.state="Running" then wscript.echo sc.name^&" - "^&sc.pathname >>sc.vbs
@echo next >>sc.vbs & cscript //nologo sc.vbs & del sc.vbs
7、显示系统最后一次启动的时间
@echo for each os in getobject _ >bt.vbs
@echo ("winmgmts://./root/cimv2:win32_operatingsystem").instances_ >>bt.vbs
@echo wscript.echo os.lastbootuptime:next >>bt.vbs & cscript //nologo bt.vbs & del bt.vbs
(责任编辑:安博涛)