@@ -47,47 +47,56 @@ public override ActionEndResult RunAction(params object[] parameter)
47
47
{
48
48
try
49
49
{
50
-
50
+ bool result = false ;
51
51
Process [ ] runningProcesses = Process . GetProcesses ( ) ;
52
+ bool processFound = false ;
53
+ CallNewLog ( new LogEntry ( $ "Searching for{ ProcessName } ...") ) ;
54
+ string searchName = ProcessName ;
55
+ if ( searchName . ToUpperInvariant ( ) . EndsWith ( ".EXE" ) )
56
+ searchName . Substring ( 0 , searchName . Length - 4 ) ;
52
57
foreach ( Process process in runningProcesses )
53
58
{
54
- if ( process . ProcessName == ProcessName )
59
+ if ( process . ProcessName == searchName )
60
+ {
55
61
try
56
62
{
57
63
CallNewLog ( new LogEntry ( $ "Closing { ProcessName } ...") ) ;
58
64
59
- bool result = process . CloseMainWindow ( ) ;
60
- if ( ! result )
61
-
62
- process . Close ( ) ;
65
+ result = process . CloseMainWindow ( ) ;
66
+ process . WaitForExit ( 3000 ) ;
63
67
}
64
68
catch ( Exception ex )
65
69
{
66
70
throw new Exception ( $ "Closing { ProcessName } failed", ex ) ;
67
71
}
68
- if ( ! process . HasExited )
69
- {
70
- if ( Force )
72
+ if ( ! process . HasExited )
71
73
{
72
- CallNewLog ( new LogEntry ( $ "Killing { ProcessName } ...") ) ;
73
- try
74
- {
75
- process . Kill ( ) ;
76
- CallNewLog ( new LogEntry ( $ "Process { ProcessName } killed..") ) ;
77
-
78
- }
79
- catch ( Exception ex )
74
+ if ( Force )
80
75
{
81
- throw new Exception ( $ "Killing { ProcessName } failed", ex ) ;
76
+ CallNewLog ( new LogEntry ( $ "Killing { ProcessName } ...") ) ;
77
+ try
78
+ {
79
+ process . Kill ( ) ;
80
+ CallNewLog ( new LogEntry ( $ "Process { ProcessName } killed..") ) ;
81
+ result = true ;
82
+
83
+ }
84
+ catch ( Exception ex )
85
+ {
86
+ throw new Exception ( $ "Killing { ProcessName } failed", ex ) ;
87
+ }
82
88
}
89
+ else
90
+ result = false ;
83
91
}
92
+ else
93
+ CallNewLog ( new LogEntry ( $ "Process { ProcessName } closed.") ) ;
84
94
}
85
- else
86
- CallNewLog ( new LogEntry ( $ "Process { ProcessName } closed.") ) ;
87
-
88
-
89
95
}
90
- return new ActionEndResult ( true ) ;
96
+ if ( ! processFound )
97
+ CallNewLog ( new LogEntry ( $ "Process { ProcessName } not found.") ) ;
98
+
99
+ return new ActionEndResult ( result ) ;
91
100
}
92
101
catch ( Exception ex )
93
102
{
0 commit comments