Esempio n. 1
0
 public static extern bool CreateProcess(
     string lpApplicationName,
     string lpCommandLine,
     ref SECURITY_ATTRIBUTES lpProcessAttributes,
     ref SECURITY_ATTRIBUTES lpThreadAttributes,
     bool bInheritHandles,
     ProcessCreationFlags dwCreationFlags,
     IntPtr lpEnvironment,
     string lpCurrentDirectory,
     [In] ref STARTUPINFO lpStartupInfo,
     out PROCESS_INFORMATION lpProcessInformation);
Esempio n. 2
0
        private static Process CreateProcessInSeparateJob(ProcessStartInfo startInfo)
        {
            var securityAttributes = new SECURITY_ATTRIBUTES
                                     {
                                         nLength = Marshal.SizeOf(typeof (SECURITY_ATTRIBUTES)),
                                         lpSecurityDescriptor = IntPtr.Zero,
                                         bInheritHandle = false
                                     };

            var environment = IntPtr.Zero;
            const bool inheritHandles = false;
            const string currentDirectory = null;
            const ProcessCreationFlags creationFlags = ProcessCreationFlags.CREATE_BREAKAWAY_FROM_JOB;

            var startupInfo = new STARTUPINFO { cb = Marshal.SizeOf(typeof (STARTUPINFO)) };
            var processInformation = new PROCESS_INFORMATION();

            PInvokeUtils.Try(() => WinAPI.CreateProcess(startInfo.FileName,
                                                        startInfo.Arguments,
                                                        ref securityAttributes,
                                                        ref securityAttributes,
                                                        inheritHandles,
                                                        creationFlags,
                                                        environment,
                                                        currentDirectory,
                                                        ref startupInfo,
                                                        out processInformation));

            try
            {
                return Process.GetProcessById(processInformation.dwProcessId);
            }
            catch (Exception e)
            {
                Logger.Error("Unable to get child process by ID.  " +
                             "Are you running in Visual Studio with Program Compatibility Assistant (PCA) enabled?  " +
                             "See http://stackoverflow.com/a/4232259/3205 for more information.", e);
                return null;
            }
        }