public Process Execute(string filename, string arguments, bool interactive, string env) { if (!this.isLocked) { throw new InvalidOperationException("This prison has to be locked before you can use it."); } if (this.used) { throw new InvalidOperationException("This prison has already been used to execute something."); } this.used = true; Native.PROCESS_INFORMATION processInfo = new Native.PROCESS_INFORMATION(); Native.ProcessCreationFlags creationFlags = Native.ProcessCreationFlags.ZERO_FLAG; creationFlags &= ~Native.ProcessCreationFlags.CREATE_PRESERVE_CODE_AUTHZ_LEVEL; creationFlags |= Native.ProcessCreationFlags.CREATE_SEPARATE_WOW_VDM | Native.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE | Native.ProcessCreationFlags.CREATE_NEW_PROCESS_GROUP | Native.ProcessCreationFlags.CREATE_SUSPENDED | Native.ProcessCreationFlags.CREATE_UNICODE_ENVIRONMENT; if (interactive) { creationFlags |= Native.ProcessCreationFlags.CREATE_NEW_CONSOLE; } else { creationFlags |= Native.ProcessCreationFlags.CREATE_NO_WINDOW; } bool startedOk = Native.CreateProcessWithLogonW( this.user.Username, ".", this.user.Password, Native.LogonFlags.LOGON_WITH_PROFILE, null, string.Format("\"{0}\" {1}", filename, arguments), creationFlags, env, this.prisonRules.PrisonHomePath, ref this.ProcessStartupInfo, out processInfo); if (!startedOk) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Process process = Process.GetProcessById(processInfo.dwProcessId); this.jobObject.AddProcess(process); uint resumeResult = Native.ResumeThread(processInfo.hThread); if (resumeResult != 1) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Native.CloseHandle(processInfo.hProcess); Native.CloseHandle(processInfo.hThread); return process; }
public Process Execute(string filename, string arguments, bool interactive, string env) { if (!this.isLocked) { throw new InvalidOperationException("This prison has to be locked before you can use it."); } if (this.used) { throw new InvalidOperationException("This prison has already been used to execute something."); } this.used = true; Native.PROCESS_INFORMATION processInfo = new Native.PROCESS_INFORMATION(); Native.ProcessCreationFlags creationFlags = Native.ProcessCreationFlags.ZERO_FLAG; creationFlags &= ~Native.ProcessCreationFlags.CREATE_PRESERVE_CODE_AUTHZ_LEVEL; creationFlags |= Native.ProcessCreationFlags.CREATE_SEPARATE_WOW_VDM | Native.ProcessCreationFlags.CREATE_DEFAULT_ERROR_MODE | Native.ProcessCreationFlags.CREATE_NEW_PROCESS_GROUP | Native.ProcessCreationFlags.CREATE_SUSPENDED | Native.ProcessCreationFlags.CREATE_UNICODE_ENVIRONMENT; if (interactive) { creationFlags |= Native.ProcessCreationFlags.CREATE_NEW_CONSOLE; } else { creationFlags |= Native.ProcessCreationFlags.CREATE_NO_WINDOW; } bool startedOk = Native.CreateProcessWithLogonW( this.user.Username, ".", this.user.Password, Native.LogonFlags.LOGON_WITH_PROFILE, null, string.Format("\"{0}\" {1}", filename, arguments), creationFlags, env, this.prisonRules.PrisonHomePath, ref this.ProcessStartupInfo, out processInfo); if (!startedOk) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Process process = Process.GetProcessById(processInfo.dwProcessId); this.jobObject.AddProcess(process); uint resumeResult = Native.ResumeThread(processInfo.hThread); if (resumeResult != 1) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Native.CloseHandle(processInfo.hProcess); Native.CloseHandle(processInfo.hThread); return(process); }