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 static extern bool CreatePipe (out SafeFileHandle hReadPipe, out SafeFileHandle hWritePipe, SECURITY_ATTRIBUTES lpPipeAttributes, int nSize);
Exemple #3
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 #4
0
		// [Xamarin] Output redirection.
		void CreateHandles (STARTUPINFO si, out SafeFileHandle outReadPipe, out SafeFileHandle errorReadPipe)
		{
			si.dwFlags |= 0x00000100; /*STARTF_USESTDHANDLES*/
			SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES ();
			sa.bInheritHandle = true;
			IntPtr curProc = NativeMethods.GetCurrentProcess ();

			SafeFileHandle outWritePipe, outReadPipeTmp;
			if (!NativeMethods.CreatePipe (out outReadPipeTmp, out outWritePipe, sa, 0))
				throw new Exception ("Pipe creation failed");

			// Create the child error pipe.
			SafeFileHandle errorWritePipe, errorReadPipeTmp;
			if (!NativeMethods.CreatePipe (out errorReadPipeTmp, out errorWritePipe, sa, 0))
				throw new Exception ("Pipe creation failed");

			// Create new output read and error read handles. Set
			// the Properties to FALSE. Otherwise, the child inherits the
			// properties and, as a result, non-closeable handles to the pipes
			// are created.
			if (!NativeMethods.DuplicateHandle (curProc, outReadPipeTmp, curProc, out outReadPipe, 0, false, NativeMethods.DUPLICATE_SAME_ACCESS))
				throw new Exception ("Pipe creation failed");
			if (!NativeMethods.DuplicateHandle (curProc, errorReadPipeTmp, curProc, out errorReadPipe, 0, false, NativeMethods.DUPLICATE_SAME_ACCESS))
				throw new Exception ("Pipe creation failed");

			NativeMethods.CloseHandle (curProc);

			// Close inheritable copies of the handles you do not want to be
			// inherited.
			outReadPipeTmp.Close ();
			errorReadPipeTmp.Close ();

			si.hStdInput = NativeMethods.GetStdHandle (NativeMethods.STD_INPUT_HANDLE);
			si.hStdOutput = outWritePipe;
			si.hStdError = errorWritePipe;
		}
Exemple #5
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 #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;
        }
 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);