• 设为首页
  • 收藏本站
  • 积分充值
  • VIP赞助
  • 手机版
  • 微博
  • 微信
    微信公众号 添加方式:
    1:搜索微信号(888888
    2:扫描左侧二维码
  • 快捷导航
    福建二哥 门户 查看主题

    vbs实现的tasklist效果代码

    发布者: 娅水9213 | 发布时间: 2025-8-14 03:36| 查看数: 103| 评论数: 0|帖子模式

    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
    核心代码
    1. Option explicit
    2. If right(Ucase(WScript.FullName),11)="WSCRIPT.EXE" Then
    3.         wscript.echo "You should run this script from the command line (cmd)" & vbCrLf & "cscript " & wscript.ScriptFullName
    4.         WScript.Quit
    5. End If

    6. dim strComputer,objWMIService,colProcesses,objProcess,ProcessTime,strCreationDate,user,Domain,strOwner,h,m,s,chaine
    7. strComputer = "."
    8. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
    9. Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process")    ' where Name='IEXPLORE.EXE'
    10. Chaine="Process   |Creation Date Time |Handles|Threads|Owner       |Priority|MemoryUsage|MaxMemUsage|MemRequired|MaxMemRequi|    Swap|  Max Swap|CPU time|PID |PFaults|Path" & vbCrLf
    11. For Each objProcess in colProcesses
    12.     If objProcess.GetOwner ( User, Domain ) = 0 Then
    13.         strOwner= Domain & "" & User
    14.     Else
    15.         strOwner="Unknown"
    16.     End If
    17.     ProcessTime=(CSng(objProcess.KernelModeTime) + CSng(objProcess.UserModeTime)) / 10000000
    18.     h=right("0" & fix(ProcessTime/60/60),2)
    19.     ProcessTime=ProcessTime-h*60*60
    20.     m=right("0" & fix(ProcessTime/60),2)
    21.     s=Right("0" & round(ProcessTime-m*60),2)
    22.     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)
    23.     If strCreationDate="// ::" Then strCreationDate=Space(19)
    24.     Chaine=Chaine & Left(objProcess.Name & space(8),12) & "|" _
    25.         & strCreationDate & "|" & Right(Space(6) & objProcess.HandleCount,7) & "|" _
    26.         & Right(Space(6) & objProcess.ThreadCount,7) & "|" _
    27.         & Left(strOwner & space(14),19) & "|" _
    28.         & Left(objProcess.Priority & Space(7),8) & "|" _
    29.         & Right(Space(10) & objProcess.PageFileUsage ,11) & "|" _
    30.         & Right(Space(10) & objProcess.PeakPageFileUsage ,11) & "|" _
    31.         & Right(Space(8) & objProcess.WorkingSetSize ,11) & "|" _
    32.         & Right(Space(8) & objProcess.PeakWorkingSetSize ,11) & "|" _
    33.         & Right(Space(10) & objProcess.VirtualSize ,11) & "|" _
    34.         & Right(Space(10) & objProcess.PeakVirtualSize ,11) & "|" _
    35.         & h & ":" & m & ":" & s & "|" _
    36.         & Left(objProcess.ProcessID & space(3),4) & "|" _
    37.         & Right(Space(6) & objProcess.PageFaults ,7) & "|" & objProcess.ExecutablePath
    38.     Chaine=Chaine & vbCrLf
    39. Next
    40. wscript.echo chaine
    复制代码
    代码运行方法,将上面的代码为tasklist.vbs
    在cmd下 cscript tasklist.vbs 即可,也可以在cmd下 cscript tasklist.vbs >list.txt直接将结果保存为list.txt查看也比较容易
    好了,代码到此结束

    来源:互联网
    免责声明:如果侵犯了您的权益,请联系站长(1277306191@qq.com),我们会及时删除侵权内容,谢谢合作!

    最新评论

    QQ Archiver 手机版 小黑屋 福建二哥 ( 闽ICP备2022004717号|闽公网安备35052402000345号 )

    Powered by Discuz! X3.5 © 2001-2023

    快速回复 返回顶部 返回列表