-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargetProcess.cs
More file actions
45 lines (41 loc) · 1.2 KB
/
Copy pathTargetProcess.cs
File metadata and controls
45 lines (41 loc) · 1.2 KB
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
using System.Diagnostics;
using System.Windows;
namespace SyncRooms
{
public class TargetProcess
{
private readonly Process? targetProcess;
public bool IsAlive = true;
public int Id = 0;
public Process? Proc;
public IntPtr Handle;
public IntPtr MainWindowHandle;
public TargetProcess(string pName)
{
try
{
Process[] ps = Process.GetProcessesByName(pName);
foreach (Process p in ps)
{
targetProcess = p;
break;
}
if (targetProcess == null)
{
IsAlive = false;
return;
}
Id = targetProcess.Id;
MainWindowHandle = targetProcess.MainWindowHandle;
Proc = targetProcess;
//Handle = targetProcess.Handle;
}
catch (Exception ex)
{
string errMsg = $"エラーが発生しています。{ex.Message}";
MessageBox.Show(errMsg);
//Application.Current.Shutdown();
}
}
}
}