51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 3058|回复: 6
打印 上一主题 下一主题

[求助] 求指点,用VBS如何获得任务管理器里应用程序的状态

[复制链接]

该用户从未签到

1#
发表于 2013-7-12 23:20:14 | 显示全部楼层
没有太清楚你的意思。不过进程信息获取。一般可以通过下面的方式获得。
1.不知道你所VBS对应操作进程可通过WMI的Win32_Process类接口获取你所需要的信息。
2.通过Wscript.Shell exec 执行命令行tasklist /v用readAll方法获取返回信息。来摘取你要的信息
回复 支持 反对

使用道具 举报

该用户从未签到

2#
发表于 2013-7-15 22:36:44 | 显示全部楼层
回复 3# deadhunter

下面是之前给一个玩游戏的朋友写过的一个脚本。获取程序状态,查找未响应的程序,如果超过60秒就强制结束进程。

  1. On Error Resume Next
  2. If LCase(Right(WScript.FullName,11)) = "wscript.exe" Then
  3.         CreateObject("Wscript.Shell").Run "CScript "&Chr(34)&WScript.ScriptFullName&Chr(34)
  4.         WScript.quit
  5. End If

  6. Timeout = 60                        '多少秒数关闭不响应程序
  7. Times = 6                                '每多少秒检测一次,时间误差为一个检测周期

  8. '################  白名单   ############## 字母用小写
  9. blist = array("system idle process","svchost.exe","conhost.exe", _
  10. "csrss.exe","explorer.exe","lsass.exe","smss.exe","lsm.exe","spoolsv.exe", _
  11. "system","wininit.exe","winlogon.exe","services.exe","taskhost.exe","dwm.exe")

  12. Set objshell = CreateObject("wscript.shell")
  13. set dc = CreateObject("Scripting.Dictionary")
  14. Do
  15.         set out = objshell.exec("cmd /c tasklist /v|find "" Not Responding """).stdout
  16.         do while Not out.AtEndOfLine
  17.                 m=out.ReadLine
  18.                 name = LCase(Trim(Left(m,23)))
  19.                 pid = Trim(Mid(m,27,8))
  20.                 b=false
  21.                 For Each n In blist
  22.                         If name = n Then b = true:Exit For
  23.                 Next
  24.                
  25.                 If Not b Then
  26.                         'WScript.Echo "At: " &Date & " " & time & ":TASKKILL  /F /PID " & pid
  27.                         If Not dc.Exists("n" & pid) Then
  28.                                 dc.Add "n" & pid,Times
  29.                         Else
  30.                                 dc.Item("n" & pid) = dc.Item("n" & pid)+Times
  31.                         End If
  32.                         If Time-lt>Times+20 Then dc.Item("n" & pid)=Times
  33.                         lt= Time

  34.                         WScript.Echo "At: " & FormatDateTime(Now,2) & " ProcessName:" & Left(m,23) & "  PID:" & Mid(m,27,8) & "  Time out: " & String(6-Len(dc.Item("n" & pid))," ") & dc.Item("n" & pid) & " Second!"
  35.                         If dc.Item("n" & pid)>=Timeout Then
  36.                                 objshell.Run "TASKKILL  /F /PID " & pid ,0
  37.                                 WScript.Echo "At: " & FormatDateTime(Now,2) &  " ProcessName:" & Left(m,23) & "  PID:" & Mid(m,27,8) & "  Execute: " & "TASKKILL  /F /PID " & pid
  38.                         End if
  39.                 End if
  40.         Loop
  41.        
  42.         WScript.Sleep Times * 1000
  43. Loop While true

复制代码
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-4 11:57 , Processed in 0.065395 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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