1 |
0932a9e2
|
Pultak
|
using System;
|
2 |
|
|
using System.Collections.Generic;
|
3 |
|
|
using System.Diagnostics;
|
4 |
|
|
using System.Linq;
|
5 |
|
|
using System.Text;
|
6 |
|
|
using System.Threading.Tasks;
|
7 |
|
|
|
8 |
|
|
namespace LDClient.detection {
|
9 |
|
|
public class ProcessUtils : IProcessUtils{
|
10 |
|
|
|
11 |
|
|
public bool IsProcessRunning(string name) {
|
12 |
|
|
return Process.GetProcessesByName(name).Length > 0;
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
public bool ExecuteNewProcess(string fileName, string argument, int timeout, int desiredExitCode) {
|
17 |
|
|
|
18 |
|
|
var t32RemProcess = new Process();
|
19 |
|
|
t32RemProcess.StartInfo.FileName = fileName;
|
20 |
|
|
t32RemProcess.StartInfo.Arguments = argument;
|
21 |
|
|
try {
|
22 |
|
|
t32RemProcess.Start();
|
23 |
|
|
if (!t32RemProcess.WaitForExit(timeout)) {
|
24 |
|
|
Program.DefaultLogger.Error($"Execution has not terminated within a predefined timeout of {timeout} ms");
|
25 |
|
|
return false;
|
26 |
|
|
}
|
27 |
|
|
if (t32RemProcess.ExitCode != desiredExitCode) {
|
28 |
|
|
Program.DefaultLogger.Error($"Execution terminated with an error code of {t32RemProcess.ExitCode}");
|
29 |
|
|
return false;
|
30 |
|
|
}
|
31 |
|
|
} catch (Exception exception) {
|
32 |
|
|
Program.DefaultLogger.Error($"Failed to run {fileName} {argument}. {exception.Message}");
|
33 |
|
|
return false;
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
return true;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
}
|
40 |
|
|
}
|