-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Pause_process.ps1
61 lines (53 loc) · 1.36 KB
/
Pause_process.ps1
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
57
58
59
60
61
# https://github.com/besimorhino/Pause-Process
function Pause-Process
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipelineByPropertyName = $true
)]
[int]
$ID
)
$Signature = @{
Namespace = "WinAPI"
Name = "Kernel"
Language = "CSharp"
MemberDefinition = @"
[DllImport("kernel32.dll")]
public static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, out bool pbDebuggerPresent);
[DllImport("kernel32.dll")]
public static extern int DebugActiveProcess(int PID);
[DllImport("kernel32.dll")]
public static extern int DebugActiveProcessStop(int PID);
"@
}
if (-not ("WinAPI.Kernel" -as [type]))
{
Add-Type @Signature
}
$ProcHandle = (Get-Process -Id $ID).Handle
$DebuggerPresent = [IntPtr]::Zero
$CallResult = [WinAPI.Kernel]::CheckRemoteDebuggerPresent($ProcHandle,[ref]$DebuggerPresent)
$PauseResult = [WinAPI.Kernel]::DebugActiveProcess($ID)
}
Pause-Process -ID (Get-Process -Name notepad).Id
# Get-Process -Name notepad | UnPause-Process
function UnPause-Process
{
[CmdletBinding()]
param
(
[Parameter(
Mandatory = $true,
ValueFromPipelineByPropertyName = $true
)]
[int]
$ID
)
$UnPauseResult = [WinAPI.Kernel]::DebugActiveProcessStop($ID)
}
UnPause-Process -ID (Get-Process -Name notepad).Id
# Get-Process -Name notepad | Pause-Process