Example #1
0
        public ProcessHandle(string commandLine)
        {
            InteropMethods.SECURITY_ATTRIBUTES empty       = default;
            InteropMethods.PROCESS_INFORMATION processInfo = default;
            var startupInfo = new InteropMethods.STARTUPINFO
            {
                cb = Marshal.SizeOf <InteropMethods.STARTUPINFO>(),
            };
            var created = InteropMethods.CreateProcess(null, commandLine, ref empty, ref empty, false,
                                                       InteropMethods.ProcessCreationFlags.CREATE_NO_WINDOW |
                                                       InteropMethods.ProcessCreationFlags.CREATE_SUSPENDED,
                                                       IntPtr.Zero, null, ref startupInfo, out processInfo);

            if (!created)
            {
                throw new ArgumentException("Can't create process");
            }

            myProcessHandle = processInfo.hProcess;
            myThreadHandle  = processInfo.hThread;
        }
Example #2
0
 public ProcessHandle(string commandLine, JobHandle job) : this(commandLine)
 {
     InteropMethods.AssignProcessToJobObject(job.Handle, myProcessHandle);
 }