forked from killswitch1111/powerguivsx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (49 loc) · 1.77 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (49 loc) · 1.77 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
46
47
48
49
50
51
52
53
54
55
56
using PowerShellTools.Common;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace PowerShell.HostService.Console
{
internal sealed class Program
{
private static AutoResetEvent _processExitEvent = new AutoResetEvent(false);
public static void Main(string[] args)
{
try
{
// Process command line args
if (args.Length != 1 || !(args[0].StartsWith(Constants.ConsoleProcessIdArg, StringComparison.OrdinalIgnoreCase)))
{
return;
}
int _powerShellHostProcessId;
if (!int.TryParse(args[0].Remove(0, Constants.ConsoleProcessIdArg.Length),
NumberStyles.None,
CultureInfo.InvariantCulture,
out _powerShellHostProcessId))
{
return;
}
// get parent process (the PowerShell host process)
Process p = Process.GetProcessById(_powerShellHostProcessId);
if (p != null)
{
p.EnableRaisingEvents = true;
// Make sure the console process terminates when host process exits.
p.Exited += new EventHandler(
(sender, eventArgs) =>
{
_processExitEvent.Set();
});
}
_processExitEvent.WaitOne();
}
catch { }
}
}
}