/// <summary> /// Creates a process in a suspended state preparing it for injection. /// </summary> /// <param name="filePath"></param> /// <param name="arguments"></param> /// <returns></returns> public static Int32 CreateSuspended(String filePath, String arguments = "") { var pi = new NativeMethods.PROCESS_INFORMATION(); var si = new NativeMethods.STARTUPINFO(); try { // Attempt to launch the file in a suspended state.. return(NativeMethods.CreateProcess(filePath, arguments, IntPtr.Zero, IntPtr.Zero, false, NativeMethods.NORMAL_PRIORITY_CLASS | NativeMethods.CREATE_SUSPENDED, IntPtr.Zero, Path.GetDirectoryName(filePath), ref si, out pi) ? pi.dwProcessId : 0); } catch { return(0); } finally { // Cleanup handles if created.. if (pi.hProcess != IntPtr.Zero) { NativeMethods.CloseHandle(pi.hProcess); } if (pi.hThread != IntPtr.Zero) { NativeMethods.CloseHandle(pi.hThread); } } }
/// <summary> /// Creates a process in a suspended state preparing it for injection. /// </summary> /// <param name="filePath"></param> /// <param name="arguments"></param> /// <returns></returns> public static Int32 CreateSuspended(String filePath, String arguments = "") { var pi = new NativeMethods.PROCESS_INFORMATION(); var si = new NativeMethods.STARTUPINFO(); try { // Attempt to launch the file in a suspended state.. return NativeMethods.CreateProcess(filePath, arguments, IntPtr.Zero, IntPtr.Zero, false, NativeMethods.NORMAL_PRIORITY_CLASS | NativeMethods.CREATE_SUSPENDED, IntPtr.Zero, Path.GetDirectoryName(filePath), ref si, out pi) ? pi.dwProcessId : 0; } catch { return 0; } finally { // Cleanup handles if created.. if (pi.hProcess != IntPtr.Zero) NativeMethods.CloseHandle(pi.hProcess); if (pi.hThread != IntPtr.Zero) NativeMethods.CloseHandle(pi.hThread); } }