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
impl Process
Sourcepub fn open(pid: u32, access: ProcessAccess) -> Result<Self>
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.
Sourcepub fn from_child(child: &Child) -> Result<Self>
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).
Sourcepub fn launch_elevated<I, S>(executable: &Path, arguments: I) -> Result<Self>
pub fn launch_elevated<I, S>(executable: &Path, arguments: I) -> Result<Self>
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.
Sourcepub fn access(&self) -> ProcessAccess
pub fn access(&self) -> ProcessAccess
The rights this handle carries.
Sourcepub fn creation_time(&self) -> Result<u64>
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.
Sourcepub fn exit_code(&self) -> Result<Option<u32>>
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.
Sourcepub fn is_app_container(&self) -> Result<bool>
pub fn is_app_container(&self) -> Result<bool>
Whether this process token is an AppContainer token.
Sourcepub fn image_path(&self) -> Result<PathBuf>
pub fn image_path(&self) -> Result<PathBuf>
The full Win32 path of the process image.
Sourcepub fn session_id(&self) -> Result<u32>
pub fn session_id(&self) -> Result<u32>
The Terminal Services session the process runs in.