数据加载中……


 

 登   陆

我的分类(专题)
数据加载中……

链接

Blog信息
数据加载中……

 



几个常用的Windows脚本
樱木花盗 发表于 2007-12-10 10:58:02

部分摘自 《Do all in cmd shell

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

显示结果的格式是:
yyyymmddHHMMSSxxxxxxZZZZ
_年_月日时分秒_微秒_时区

8,显示系统运行时间

@echo for each os in getobject _ >rt.vbs
@echo ("winmgmts:\\.\root\cimv2:win32_perfrawdata_perfos_system").instances_ >>rt.vbs
@echo s=os.timestamp_sys100ns:l=len(s):s=left(s,l-7):for i=1 to l-7 >>rt.vbs
@echo t=t^&mid(s,i,1):d=t\86400:r=r^&d:t=t mod 86400:next >>rt.vbs
@echo wscript.echo cint(r)^&"d "^&t\3600^&"h "^&t\60 mod 60^&"m "^&t mod 60^&"s":next >>rt.vbs
cscript //nologo rt.vbs & del rt.vbs

这个运行时间是从性能计数器中获得的64位整型数,不会出现在49.7天后溢出的情况。

7,添加用户

dim server_name,user_name,user_pwd
server_name ="127.0.0.1"
user_name="ray"
user_pwd="ray"
On Error Resume Next

Set Domain = GetObject("WinNT://" & server_name)
Set TheUser = Domain.Create ("user", user_name)
If err.number = 0 Then
TheUser.SetInfo
TheUser.SetPassword User_pwd

Set TheGroup = GetObject("WinNT://" & server_name & "/Administrators")
Set TheUser = GetObject("WinNT://" & user_name & "")
TheGroup.Add(TheUser.ADsPath)
End If

 


阅读全文 | 回复(0) | 引用通告 | 编辑
 


发表评论:

    昵称:
    密码: (游客无须输入密码)
    主页:
    标题:
    数据加载中……


Powered by Oblog.