■ OpenProcess API 함수를 선언하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using System; using System.Runtime.InteropServices; #region 프로세스 열기 - OpenProcess(processAccessFlag, inheritHandle, processID) /// <summary> /// 프로세스 열기 /// </summary> /// <param name="processAccessFlag">프로세스 액세스 플래그</param> /// <param name="inheritHandle">핸들 상속 여부</param> /// <param name="processID">프로세스 ID</param> /// <returns>프로세스 핸들</returns> [DllImport("kernel32", SetLastError = true)] private static extern IntPtr OpenProcess(ProcessAccessFlag processAccessFlag, bool inheritHandle, int processID); #endregion /// <summary> /// 프로세스 액세스 플래그 /// </summary> [Flags] public enum ProcessAccessFlag : uint { /// <summary> /// All /// </summary> All = 0x001f0fff, /// <summary> /// Terminate /// </summary> Terminate = 0x00000001, /// <summary> /// CreateThread /// </summary> CreateThread = 0x00000002, /// <summary> /// VirtualMemoryOperation /// </summary> VirtualMemoryOperation = 0x00000008, /// <summary> /// VirtualMemoryRead /// </summary> VirtualMemoryRead = 0x00000010, /// <summary> /// VirtualMemoryWrite /// </summary> VirtualMemoryWrite = 0x00000020, /// <summary> /// DuplicateHandle /// </summary> DuplicateHandle = 0x00000040, /// <summary> /// CreateProcess /// </summary> CreateProcess = 0x000000080, /// <summary> /// SetQuota /// </summary> SetQuota = 0x00000100, /// <summary> /// SetInformation /// </summary> SetInformation = 0x00000200, /// <summary> /// QueryInformation /// </summary> QueryInformation = 0x00000400, /// <summary> /// QueryLimitedInformation /// </summary> QueryLimitedInformation = 0x00001000, /// <summary> /// Synchronize /// </summary> Synchronize = 0x00100000 } |