Skip to main content

Process

Struct Process 

Source
pub struct Process { /* private fields */ }
Expand description

An open process handle with a fixed rights set.

The handle names one process object for its whole life, so unlike a PID it cannot start pointing at an unrelated process after the original exits.

Implementations§

Source§

impl Process

Source

pub fn open(pid: u32, access: ProcessAccess) -> Result<Self>

Opens pid with exactly access. The error carries the Win32 code; a PID that has left the process table reports ERROR_INVALID_PARAMETER.

Source

pub fn from_child(child: &Child) -> Result<Self>

Duplicates the handle std holds for child. The result keeps every right CreateProcess granted (job assignment and termination among them, which a reopen by PID would not get).

Source

pub fn launch_elevated<I, S>(executable: &Path, arguments: I) -> Result<Self>
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Starts executable through the shell’s runas verb, which shows the elevation prompt, and returns the process the shell created.

Each argument is quoted the way CommandLineToArgvW parses it, so it reaches the child unchanged. The child’s window starts hidden. A user who declines the prompt makes this fail with ERROR_CANCELLED (1223) as the Win32 code.

The shell may need COM: call this from a thread that has initialized COM if the target is not a plain executable.

Source

pub fn access(&self) -> ProcessAccess

The rights this handle carries.

Source

pub fn pid(&self) -> Result<u32>

The process identifier behind the handle.

Source

pub fn creation_time(&self) -> Result<u64>

The creation time as a 64-bit FILETIME value. Together with the PID it identifies a process across its whole lifetime, which a PID alone does not, since Windows reuses PIDs.

Source

pub fn exit_code(&self) -> Result<Option<u32>>

The exit code, or None while the process is still running.

A process may itself exit with code 259 (STILL_ACTIVE). When the handle carries SYNCHRONIZE, a zero-length wait tells that case apart from a running process; without it, 259 is reported as running.

Source

pub fn is_app_container(&self) -> Result<bool>

Whether this process token is an AppContainer token.

Source

pub fn image_path(&self) -> Result<PathBuf>

The full Win32 path of the process image.

Source

pub fn session_id(&self) -> Result<u32>

The Terminal Services session the process runs in.

Source

pub fn terminate(&self, exit_code: u32) -> Result<()>

Terminates the process with exit_code.

Source

pub fn wait(&self, timeout: Option<Duration>) -> Result<WaitOutcome>

Waits for the process to exit. None waits forever.

Trait Implementations§

Source§

impl AsHandle for Process

Source§

fn as_handle(&self) -> BorrowedHandle<'_>

Borrows the handle. Read more
Source§

impl AsRawHandle for Process

Source§

fn as_raw_handle(&self) -> RawHandle

Extracts the raw handle. Read more
Source§

impl Debug for Process

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Process> for OwnedHandle

Source§

fn from(process: Process) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.