public CorProcess CreateProcess( String applicationName, String commandLine, SECURITY_ATTRIBUTES processAttributes, SECURITY_ATTRIBUTES threadAttributes, bool inheritHandles, int creationFlags, IntPtr environment, String currentDirectory, STARTUPINFO startupInfo, ref PROCESS_INFORMATION processInformation, CorDebugCreateProcessFlags debuggingFlags) { /* * If commandLine is: <c:\a b\a arg1 arg2> and c:\a.exe does not exist, * then without this logic, "c:\a b\a.exe" would be tried next. * To prevent this ambiguity, this forces the user to quote if the path * has spaces in it: <"c:\a b\a" arg1 arg2> */ if (null == applicationName && !commandLine.StartsWith("\"")) { int firstSpace = commandLine.IndexOf(" "); if (firstSpace != -1) commandLine = String.Format(CultureInfo.InvariantCulture, "\"{0}\" {1}", commandLine.Substring(0, firstSpace), commandLine.Substring(firstSpace, commandLine.Length - firstSpace)); } ICorDebugProcess proc = null; m_debugger.CreateProcess( applicationName, commandLine, processAttributes, threadAttributes, inheritHandles ? 1 : 0, (uint) creationFlags, environment, currentDirectory, startupInfo, processInformation, debuggingFlags, out proc); return CorProcess.GetCorProcess(proc); }
/** * Launch a process under the control of the debugger. * * Parameters are the same as the Win32 CreateProcess call. */ public CorProcess CreateProcess( String applicationName, String commandLine, String currentDirectory, int flags ) { var pi = new PROCESS_INFORMATION(); var si = new STARTUPINFO(); si.cb = Marshal.SizeOf(si); // initialize safe handles si.hStdInput = new SafeFileHandle(new IntPtr(0), false); si.hStdOutput = new SafeFileHandle(new IntPtr(0), false); si.hStdError = new SafeFileHandle(new IntPtr(0), false); CorProcess ret; //constrained execution region (Cer) RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { ret = CreateProcess( applicationName, commandLine, null, null, true, // inherit handles flags, // creation flags new IntPtr(0), // environment currentDirectory, si, // startup info ref pi, // process information CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS); NativeMethods.CloseHandle(pi.hProcess); NativeMethods.CloseHandle(pi.hThread); } return ret; }