예제 #1
0
        public static SystemDebugger CreateProcess(string command)
        {
            // CreateProcess
            UnsafeMethods.STARTUPINFO         startUpInfo        = new UnsafeMethods.STARTUPINFO();
            UnsafeMethods.PROCESS_INFORMATION processInformation = new UnsafeMethods.PROCESS_INFORMATION();

            if (!UnsafeMethods.CreateProcess(
                    null,                               // lpApplicationName
                    command,                            // lpCommandLine
                    0,                                  // lpProcessAttributes
                    0,                                  // lpThreadAttributes
                    false,                              // bInheritHandles
                    DEBUG_PROCESS,                      // dwCreationFlags, DEBUG_PROCESS
                    IntPtr.Zero,                        // lpEnvironment
                    null,                               // lpCurrentDirectory
                    ref startUpInfo,                    // lpStartupInfo
                    out processInformation))            // lpProcessInformation
            {
                var ex = new Win32Exception(Marshal.GetLastWin32Error());
                throw new PeachException("System debugger could not start process '" + command + "'.  " + ex.Message, ex);
            }

            UnsafeMethods.CloseHandle(processInformation.hProcess);
            UnsafeMethods.CloseHandle(processInformation.hThread);
            UnsafeMethods.DebugSetProcessKillOnExit(true);

            return(new SystemDebugger(processInformation.dwProcessId));
        }
예제 #2
0
 protected SystemDebugger(UnsafeMethods.STARTUPINFO startUpInfo, UnsafeMethods.PROCESS_INFORMATION processInformation)
 {
     _startUpInfo        = startUpInfo;
     _processInformation = processInformation;
     dwProcessId         = processInformation.dwProcessId;
 }