Exemple #1
0
 public static extern int CreateProcess(
     string applicationName,
     string commandLine,
     SECURITY_ATTRIBUTES processAttributes,
     SECURITY_ATTRIBUTES threadAttributes,
     bool bInheritHandles,
     int dwCreationFlags,
     IntPtr environment,
     string currentDirectory,
     STARTUPINFO startupInfo,
     PROCESS_INFORMATION processInformation);
Exemple #2
0
        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);
        }
Exemple #3
0
		// [Xamarin] ASP.NET Debugging and output redirection.
        /**
         * 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,
										 IDictionary<string,string> environment,
                                         int    flags
                                         )
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION ();

            STARTUPINFO si = new STARTUPINFO ();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
			SafeFileHandle outReadPipe = null, errorReadPipe = null;
			if ((flags & CREATE_REDIRECT_STD) != 0) {
				CreateHandles (si, out outReadPipe, out errorReadPipe);
				flags &= ~CREATE_REDIRECT_STD;
			}
			else {
				si.hStdInput = new SafeFileHandle (IntPtr.Zero, false);
				si.hStdOutput = new SafeFileHandle (IntPtr.Zero, false);
				si.hStdError = new SafeFileHandle (IntPtr.Zero, false);
			}

			IntPtr env = IntPtr.Zero;
			if (environment != null) {
				string senv = null;
				foreach (KeyValuePair<string, string> var in environment) {
					senv += var.Key + "=" + var.Value + "\0";
				}
				senv += "\0";
				env = Marshal.StringToHGlobalAnsi (senv);
			}

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try 
            {
            } 
            finally
            {
                ret = CreateProcess (
                                     applicationName,
                                     commandLine, 
                                     null,
                                     null,
                                     true,   // inherit handles
                                     flags,  // creation flags
									 env,      // environment
                                     currentDirectory,
                                     si,     // startup info
                                     ref pi, // process information
                                     CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS);
                NativeMethods.CloseHandle (pi.hProcess);
                NativeMethods.CloseHandle (pi.hThread);
            }

			if (env != IntPtr.Zero)
				Marshal.FreeHGlobal (env);

			if (outReadPipe != null) {

				// Close pipe handles (do not continue to modify the parent).
				// You need to make sure that no handles to the write end of the
				// output pipe are maintained in this process or else the pipe will
				// not close when the child process exits and the ReadFile will hang.

				si.hStdInput.Close ();
				si.hStdOutput.Close ();
				si.hStdError.Close ();

				ret.TrackStdOutput (outReadPipe, errorReadPipe);
			}

			return ret;
        }
Exemple #4
0
 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)
 {
     return CreateProcess(null,
                          applicationName,
                          commandLine,
                          processAttributes,
                          threadAttributes,
                          inheritHandles,
                          creationFlags,
                          environment,
                          currentDirectory,
                          startupInfo,
                          ref processInformation,
                          debuggingFlags);
 }
Exemple #5
0
        public CorProcess CreateProcess(String applicationName,
                                        String commandLine,
                                        String currentDirectory,
                                        int flags,
                                        CorRemoteTarget target)
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();

            STARTUPINFO si = new STARTUPINFO();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
            si.hStdInput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdOutput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdError = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                ret = CreateProcess(target,
                                     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;
        }
Exemple #6
0
        public static int CreateProc(
            string applicationName,
            string commandLine,
            SECURITY_ATTRIBUTES processAttributes,
            SECURITY_ATTRIBUTES threadAttributes,
            bool bInheritHandles,
            int dwCreationFlags,
            IntPtr environment,
            string currentDirectory,
            STARTUPINFO startupInfo,
            ref PROCESS_INFORMATION processInformation)
        {
            int iRet = NativeMethods.CreateProcess(
                                applicationName,
                                commandLine,
                                processAttributes,
                                threadAttributes,
                                bInheritHandles,
                                dwCreationFlags,
                                environment,
                                currentDirectory,
                                startupInfo,
                                processInformation);

            if (0 == iRet)
            {
                CommandBase.WriteError("CreateProcess failed in Silverlight Extension: " + Marshal.GetLastWin32Error());
                CommandBase.WriteError("    CreateProcess-ApplicationName=" + applicationName);
                CommandBase.WriteError("    CreateProcess-commandLine=" + commandLine);
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return iRet;
        }
        /**
         * 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,
										 IDictionary<string,string> environment,
                                         int    flags
                                         )
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION ();

            STARTUPINFO si = new STARTUPINFO ();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
			// [Xamarin] ASP.NET Debugging and output redirection.
			SafeFileHandle outReadPipe = null, errorReadPipe = null;
			DebuggerExtensions.SetupOutputRedirection (si, ref flags, out outReadPipe, out errorReadPipe);
			IntPtr env = DebuggerExtensions.SetupEnvironment (environment);

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try 
            {
            } 
            finally
            {
                ret = CreateProcess (
                                     applicationName,
                                     commandLine, 
                                     null,
                                     null,
                                     true,   // inherit handles
                                     flags,  // creation flags
									 env,      // environment
                                     currentDirectory,
                                     si,     // startup info
                                     ref pi, // process information
                                     CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS);
                NativeMethods.CloseHandle (pi.hProcess);
                NativeMethods.CloseHandle (pi.hThread);
            }

			DebuggerExtensions.TearDownEnvironment (env);
			DebuggerExtensions.TearDownOutputRedirection (outReadPipe, errorReadPipe, si, ret);

            return ret;
        }
 public virtual extern void CreateProcess([In, MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, [In] SECURITY_ATTRIBUTES lpProcessAttributes, [In] SECURITY_ATTRIBUTES lpThreadAttributes, [In] int bInheritHandles, [In] uint dwCreationFlags, [In] IntPtr lpEnvironment, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCurrentDirectory, [In, ComAliasName("Microsoft.Debugging.CorDebug.NativeApi.ULONG_PTR")] STARTUPINFO lpStartupInfo, [In, ComAliasName("Microsoft.Debugging.CorDebug.NativeApi.ULONG_PTR")] PROCESS_INFORMATION lpProcessInformation, [In] CorDebugCreateProcessFlags debuggingFlags, [MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess);