@@ -47,47 +47,56 @@ public override ActionEndResult RunAction(params object[] parameter)
4747 {
4848 try
4949 {
50-
50+ bool result = false ;
5151 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 ) ;
5257 foreach ( Process process in runningProcesses )
5358 {
54- if ( process . ProcessName == ProcessName )
59+ if ( process . ProcessName == searchName )
60+ {
5561 try
5662 {
5763 CallNewLog ( new LogEntry ( $ "Closing { ProcessName } ...") ) ;
5864
59- bool result = process . CloseMainWindow ( ) ;
60- if ( ! result )
61-
62- process . Close ( ) ;
65+ result = process . CloseMainWindow ( ) ;
66+ process . WaitForExit ( 3000 ) ;
6367 }
6468 catch ( Exception ex )
6569 {
6670 throw new Exception ( $ "Closing { ProcessName } failed", ex ) ;
6771 }
68- if ( ! process . HasExited )
69- {
70- if ( Force )
72+ if ( ! process . HasExited )
7173 {
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 )
8075 {
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+ }
8288 }
89+ else
90+ result = false ;
8391 }
92+ else
93+ CallNewLog ( new LogEntry ( $ "Process { ProcessName } closed.") ) ;
8494 }
85- else
86- CallNewLog ( new LogEntry ( $ "Process { ProcessName } closed.") ) ;
87-
88-
8995 }
90- return new ActionEndResult ( true ) ;
96+ if ( ! processFound )
97+ CallNewLog ( new LogEntry ( $ "Process { ProcessName } not found.") ) ;
98+
99+ return new ActionEndResult ( result ) ;
91100 }
92101 catch ( Exception ex )
93102 {
0 commit comments