frederik, Где-то Dragokas давал такой код
Windows Batch file |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
| nircmd win hide class "ConsoleWindowClass"
color 1a
title Сообщение
mode con cols=30 lines=3
@echo off&:: by Alex Dragokas -05.01.13-
SetLocal EnableDelayedExpansion EnableExtensions
::Name of a watching processes (separeted by ,)
Set ProcNames=example.exe,example2.exe
::Delay (ms.) before the next check
Set /A DelayNewCheck=5000
::Delay (ms.) before starting a process after shutting down because of "not responding" status
Set DelayStartProcess=3000
::Setting Priority of Application to Run with (1 to 6):
::1 - LOW, 2 - BELOWNORMAL, 3 - NORMAL, 4 - ABOVENORMAL, 5 - HIGH, 6 - REALTIME
Set Priority=3
::Start the process in Minimize mode? (1 - Yes, 2 - No)
Set Minimize=1
::Delay (ms.) before checking for using of memory
::Set MemDelay=10000
::Count of bytes that application need to use after 3 + %MemDelay% ms. of new running.
::Set MinMemory=200000000
::ForceMinimizeOptions (with NirCMD utility). Recognizing by class or title of window (or part of it)
::Set WinClass=IW5 WinConsole
::Set WinTitle=Call of Duty
::The time (ms.) while we checking if a process really not responding all this time
Set /A BugTime=10000
::How many times we make a series of chekings (during %BugTime%)
Set /A BugChecks=10
Set /A BugIntervals=%BugChecks% - 1
Set /A BugIntervalsDelay=%BugTime% / %BugIntervals%
Call :PriorityEnum %Priority% Priority
if %Minimize%==1 (set Minimize=/MIN ) else (set Minimize=)
Set ProcNames="%ProcNames:,=" "%"
:begin
For %%A in (%ProcNames%) do call :WatchSingleProcess "%%~A"
Call :Delay %DelayNewCheck%
Goto :begin
:WatchSingleProcess %1-Name_of_Process
Set Process=%~1
Call :IsResponding "%Process%"
Set PID=%errorlevel%
if %PID% neq 0 (
Call :GetProcessInfo "%PID%" "%Process%" ProcessPath Param
<nul set /p test=Found Bug in %Process% PID=%PID% %ProcessPath%
for /L %%C in (1,1,%BugChecks%) do (
Call :IsResponding "%Process%"
if !errorlevel! neq 0 (
<nul set /p test=.
if %%C==%BugChecks% (Call :Restart "%PID%" "%Process%"& Exit /B)
Call :Delay %BugIntervalsDelay%
) else (
Echo Waked up
Exit /B
)
)
)
Exit /B
:Delay %1-msec.
if "%1"=="" Exit /B
ping 192.168.254.254 -n 2 -w %~1 > nul
Exit /B
:IsResponding %1-ProcessName
For /f "tokens=1,2 delims=," %%A in (
'tasklist /FI "IMAGENAME eq %~1" /FI "STATUS eq NOT RESPONDING" /FO CSV /NH') do (
if /i "%%~A"=="%~1" Exit /B %%~B
)
Exit /B 0
:Restart %1-Proccess_PID %2-Process_Name
Echo ShutDown
Call :GetProcessInfo "%~1" "%~2" ProcessPath Param
taskkill /F /PID %~1
Call :Delay %DelayStartProcess%
pushd "%ProcessPath%"
start "" %Minimize%/%Priority% "%ProcessPath%\%~2" %Param%
popd
Echo %ProcessFullName% started.
::Delay before minimize by NirCMD utility
Call :Delay 3000
if defined WinTitle nircmd win min ititle "%WinTitle%"
if defined WinClass nircmd win min class "%WinClass%"
Call :Delay %MemDelay%
if defined MinMemory (
tasklist /FI "IMAGENAME eq %~2" /FI "PID eq %~1" /FI "MEMUSAGE lt %MemDelay%" /FO CSV /NH|Find /i "%~2"&&(
Call :Restart "%~1" "%~2"
))
Exit /B
:PriorityEnum %1-Constant %2-var.name
if %~1==1 Set %~2=LOW
if %~1==2 Set %~2=BELOWNORMAL
if %~1==3 Set %~2=NORMAL
if %~1==4 Set %~2=ABOVENORMAL
if %~1==5 Set %~2=HIGH
if %~1==6 Set %~2=REALTIME
Exit /B
:GetProcessInfo %1-Proccess_PID %2-Process_Name %3-var.Process_Path %4-var.Process_Parameters
::Getting the Process' Path and Parameters
for /f "tokens=1* delims==" %%A in (
'wmic path win32_process where ^(ProcessID^=%~1 and name^="%~2"^) get "CommandLine"^,"ExecutablePath" /value^|findstr /BC:"CommandLine" /C:"ExecutablePath"') do (
if "%%A"=="CommandLine" Set ProcParse=%%B
if "%%A"=="ExecutablePath" Set ProcessPath=%%~dpB
)
Set %3=%ProcessPath:~0,-1%
::Parse Parameters
Set /A n=0& Set Param=
for %%A in (%ProcParse%) do Set /A n+=1& if !n! neq 1 (Set Param=!Param!%%A )
Set %4=%Param:~0,-1%
Exit /B |
|
- он убивает зависший процесс, но не просто и не совсем, а пытается запустить его, если возможно, пока он не "отвиснет".