当前位置: 代码网 > it编程>前端脚本>其它脚本 > vbs实现的tasklist效果代码

vbs实现的tasklist效果代码

2024年05月18日 其它脚本 我要评论
this short script uses wmi to display the same information than in the tool "tasklist", but dumping

this short script uses wmi to display the same information than in the tool "tasklist", but dumping the result on the console. it can dump remote tasks running on another computer,
这个简短的脚本使用wmi显示与工具“tasklist”中相同的信息,但只有在命令行下输出结果。它也可以在另一台计算机上查看远程任务,
文件名:tasklist.vbs
要求:无
作者:jean-luc antoine
提交日期:2005年7月14日
类别:4k

核心代码

option explicit 
if right(ucase(wscript.fullname),11)="wscript.exe" then
	wscript.echo "you should run this script from the command line (cmd)" & vbcrlf & "cscript " & wscript.scriptfullname
	wscript.quit
end if

dim strcomputer,objwmiservice,colprocesses,objprocess,processtime,strcreationdate,user,domain,strowner,h,m,s,chaine
strcomputer = "." 
set objwmiservice = getobject("winmgmts:" & "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2") 
set colprocesses = objwmiservice.execquery ("select * from win32_process")    ' where name='iexplore.exe' 
chaine="process   |creation date time |handles|threads|owner       |priority|memoryusage|maxmemusage|memrequired|maxmemrequi|    swap|  max swap|cpu time|pid |pfaults|path" & vbcrlf 
for each objprocess in colprocesses 
    if objprocess.getowner ( user, domain ) = 0 then 
        strowner= domain & "\" & user 
    else 
        strowner="unknown" 
    end if 
    processtime=(csng(objprocess.kernelmodetime) + csng(objprocess.usermodetime)) / 10000000 
    h=right("0" & fix(processtime/60/60),2) 
    processtime=processtime-h*60*60 
    m=right("0" & fix(processtime/60),2) 
    s=right("0" & round(processtime-m*60),2) 
    strcreationdate=mid(objprocess.creationdate,7,2) & "/" & mid(objprocess.creationdate,5,2) & "/" & left(objprocess.creationdate,4) & " " & mid(objprocess.creationdate,9,2) & ":" & mid(objprocess.creationdate,11,2) & ":" & mid(objprocess.creationdate,13,2) 
    if strcreationdate="// ::" then strcreationdate=space(19) 
    chaine=chaine & left(objprocess.name & space(8),12) & "|" _ 
        & strcreationdate & "|" & right(space(6) & objprocess.handlecount,7) & "|" _ 
        & right(space(6) & objprocess.threadcount,7) & "|" _ 
        & left(strowner & space(14),19) & "|" _ 
        & left(objprocess.priority & space(7),8) & "|" _ 
        & right(space(10) & objprocess.pagefileusage ,11) & "|" _ 
        & right(space(10) & objprocess.peakpagefileusage ,11) & "|" _ 
        & right(space(8) & objprocess.workingsetsize ,11) & "|" _ 
        & right(space(8) & objprocess.peakworkingsetsize ,11) & "|" _ 
        & right(space(10) & objprocess.virtualsize ,11) & "|" _ 
        & right(space(10) & objprocess.peakvirtualsize ,11) & "|" _ 
        & h & ":" & m & ":" & s & "|" _ 
        & left(objprocess.processid & space(3),4) & "|" _ 
        & right(space(6) & objprocess.pagefaults ,7) & "|" & objprocess.executablepath 
    chaine=chaine & vbcrlf 
next 
wscript.echo chaine

代码运行方法,将上面的代码为tasklist.vbs

在cmd下 cscript tasklist.vbs 即可,也可以在cmd下 cscript tasklist.vbs >list.txt直接将结果保存为list.txt查看也比较容易

好了,代码到此结束

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com