|
之前帮一个玩游戏的朋友写的一个小脚本。检测未相应程序并关闭的
- On Error Resume Next
- If LCase(Right(WScript.FullName,11)) = "wscript.exe" Then
- CreateObject("Wscript.Shell").Run "CScript "&Chr(34)&WScript.ScriptFullName&Chr(34)
- WScript.quit
- End If
- Timeout = 60 '多少秒数关闭不响应程序
- Times = 6 '每多少秒检测一次,时间误差为一个检测周期
- '################ 白名单 ############## 字母用小写
- blist = array("system idle process","svchost.exe","conhost.exe", _
- "csrss.exe","explorer.exe","lsass.exe","smss.exe","lsm.exe","spoolsv.exe", _
- "system","wininit.exe","winlogon.exe","services.exe","taskhost.exe","dwm.exe")
- Set objshell = CreateObject("wscript.shell")
- set dc = CreateObject("Scripting.Dictionary")
- Do
- set out = objshell.exec("cmd /c tasklist /v|find "" Not Responding """).stdout
- do while Not out.AtEndOfLine
- m=out.ReadLine
- name = LCase(Trim(Left(m,23)))
- pid = Trim(Mid(m,27,8))
- b=false
- For Each n In blist
- If name = n Then b = true:Exit For
- Next
-
- If Not b Then
- 'WScript.Echo "At: " &Date & " " & time & ":TASKKILL /F /PID " & pid
- If Not dc.Exists("n" & pid) Then
- dc.Add "n" & pid,Times
- Else
- dc.Item("n" & pid) = dc.Item("n" & pid)+Times
- End If
- If Time-lt>Times+20 Then dc.Item("n" & pid)=Times
- lt= Time
- 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!"
- If dc.Item("n" & pid)>=Timeout Then
- objshell.Run "TASKKILL /F /PID " & pid ,0
- WScript.Echo "At: " & FormatDateTime(Now,2) & " ProcessName:" & Left(m,23) & " PID:" & Mid(m,27,8) & " Execute: " & "TASKKILL /F /PID " & pid
- End if
- End if
- Loop
-
- WScript.Sleep Times * 1000
- Loop While true
复制代码 |
|