Repository navigation
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
55 lines (49 loc) · 1.92 KB
/
Copy pathNativeMethods.cs
File metadata and controls
55 lines (49 loc) · 1.92 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
using System;
using System.Runtime.InteropServices;
namespace ProcessFreezer
{
/// <summary>
/// Windows API P/Invoke 定义
/// </summary>
public static class NativeMethods
{
// 进程访问权限
public const uint PROCESS_QUERY_INFORMATION = 0x0400;
public const uint PROCESS_SET_QUOTA = 0x0100;
public const uint PROCESS_VM_READ = 0x0010;
/// <summary>
/// 清空进程工作集(将物理内存页面写入页面文件)
/// </summary>
[DllImport("psapi.dll", SetLastError = true)]
public static extern bool EmptyWorkingSet(IntPtr hProcess);
/// <summary>
/// 打开进程句柄
/// </summary>
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
/// <summary>
/// 关闭句柄
/// </summary>
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject);
/// <summary>
/// 获取进程内存信息
/// </summary>
[DllImport("psapi.dll", SetLastError = true)]
public static extern bool GetProcessMemoryInfo(IntPtr hProcess, out PROCESS_MEMORY_COUNTERS counters, uint size);
[StructLayout(LayoutKind.Sequential)]
public struct PROCESS_MEMORY_COUNTERS
{
public uint cb;
public uint PageFaultCount;
public UIntPtr PeakWorkingSetSize;
public UIntPtr WorkingSetSize;
public UIntPtr QuotaPeakPagedPoolUsage;
public UIntPtr QuotaPagedPoolUsage;
public UIntPtr QuotaPeakNonPagedPoolUsage;
public UIntPtr QuotaNonPagedPoolUsage;
public UIntPtr PagefileUsage;
public UIntPtr PeakPagefileUsage;
}
}
}