public static extern bool CreateProcess( [MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, ProcessCreationFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
public static Process CreateProcessWithFlags(this ProcessStartInfo startInfo, ProcessCreationFlags creationFlags) { if (string.IsNullOrEmpty(startInfo.FileName)) throw new ArgumentException("No FileName was specified in ProcessStartInfo", "startInfo"); if (!File.Exists(startInfo.FileName)) throw new FileNotFoundException("Unable to find the specified the process file", startInfo.FileName); var startupInfo = new STARTUPINFO(); startupInfo.cb = Marshal.SizeOf(startupInfo); var args = string.IsNullOrEmpty(startInfo.Arguments) ? null : new StringBuilder(startInfo.Arguments); var workingDirectory = string.IsNullOrEmpty(startInfo.WorkingDirectory) ? null : startInfo.WorkingDirectory; var procInfo = new PROCESS_INFORMATION(); if (!Imports.CreateProcess(startInfo.FileName, args, IntPtr.Zero, IntPtr.Zero, false, creationFlags, IntPtr.Zero, workingDirectory, ref startupInfo, out procInfo)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } var ret = Process.GetProcessById(procInfo.dwProcessId); ProcessMemoryManager.ForProcess(ret).MainThreadId = procInfo.dwThreadId; return ret; }