■ CreateProcess 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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
using System; using System.Runtime.InteropServices; #region 프로세스 생성하기 - CreateProcess(applicationName, commandLine, processAttributes, threadAttributes, inheritHandles, creationFlag, environmentHandle, currentDirectoryPath, startupInfo, processInformation) /// <summary> /// 프로세스 생성하기 /// </summary> /// <param name="applicationName">애플리케이션명</param> /// <param name="commandLine">명령줄</param> /// <param name="processAttributes">프로세스 어트리뷰트</param> /// <param name="threadAttributes">스레드 어트리뷰트</param> /// <param name="inheritHandles">핸들 상속 여부</param> /// <param name="creationFlag">생성 플래그</param> /// <param name="environmentHandle">환경 핸들</param> /// <param name="currentDirectoryPath">현재 디렉토리 경로</param> /// <param name="startupInfo">시작시 정보</param> /// <param name="processInformation">프로세스 정보</param> /// <returns>처리 결과</returns> [DllImport("kernel32")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool CreateProcess ( string applicationName, string commandLine, ref SECURITY_ATTRIBUTES processAttributes, ref SECURITY_ATTRIBUTES threadAttributes, bool inheritHandles, uint creationFlag, IntPtr environmentHandle, string currentDirectoryPath, [In] ref STARTUPINFOEX startupInfo, out PROCESS_INFORMATION processInformation ); #endregion /// <summary> /// 보안 어트리뷰트 /// </summary> [StructLayout(LayoutKind.Sequential)] public struct SECURITY_ATTRIBUTES { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 길이 /// </summary> public int Length; /// <summary> /// 보안 설명자 /// </summary> public IntPtr SecurityDescriptor; /// <summary> /// 핸들 상속 여부 /// </summary> [MarshalAs(UnmanagedType.Bool)] public bool InheritHandle; #endregion } /// <summary> /// 시작시 정보 /// </summary> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct STARTUPINFO { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 바이트 카운트 /// </summary> public int ByteCount; /// <summary> /// 예약 /// </summary> public string Reserved; /// <summary> /// 데스크톱 /// </summary> public string Desktop; /// <summary> /// 제목 /// </summary> public string Title; /// <summary> /// X /// </summary> public int X; /// <summary> /// Y /// </summary> public int Y; /// <summary> /// X 크기 /// </summary> public int XSize; /// <summary> /// Y 크기 /// </summary> public int YSize; /// <summary> /// X 문자 카운트 /// </summary> public int XCountCharacters; /// <summary> /// Y 문자 카운트 /// </summary> public int YCountCharacters; /// <summary> /// 칠하기 어트리뷰트 /// </summary> public int FillAttribute; /// <summary> /// 플래그 /// </summary> public int Flag; /// <summary> /// 윈도우 표시 /// </summary> public short ShowWindow; /// <summary> /// 예약 2 바이트 카운트 /// </summary> public short Reserved2ByteCount; /// <summary> /// 예약 2 핸들 /// </summary> public IntPtr Reserved2Handle; /// <summary> /// 표준 입력 핸들 /// </summary> public IntPtr StandardInputHandle; /// <summary> /// 표준 출력 핸들 /// </summary> public IntPtr StandardOutputHandle; /// <summary> /// 표준 에러 핸들 /// </summary> public IntPtr StandardErrorHandle; #endregion } /// <summary> /// 시작시 정보 (확장) /// </summary> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct STARTUPINFOEX { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 시작시 정보 /// </summary> public STARTUPINFO StartupInfo; /// <summary> /// 어트리뷰트 리스트 핸들 /// </summary> public IntPtr AttributeListHandle; #endregion } |