Expand description
Process operations and management.
This module provides ergonomic access to Windows process APIs including:
- Opening and querying processes
- Reading PEB (Process Environment Block) data
- Enumerating threads and modules
- Process tree operations
- Memory information
§Examples
§Opening and querying a process
use windows_erg::process::{Process, ProcessId};
let process = Process::open(ProcessId::new(1234))?;
println!("Process name: {}", process.name()?);
println!("Process path: {}", process.path()?.display());§Reading PEB data
use windows_erg::process::Process;
let process = Process::current();
println!("Command line: {}", process.command_line()?);
let env = process.environment()?;
for (key, value) in env {
println!("{} = {}", key, value);
}§Listing all processes
use windows_erg::process::Process;
let processes = Process::list()?;
for proc in processes {
println!("{}: {}", proc.pid, proc.name);
}§Using buffer reuse for performance
use windows_erg::process::Process;
let processes = Process::list()?;
let mut buffer = Vec::with_capacity(8192);
for proc_info in processes {
if let Ok(process) = Process::open(proc_info.pid) {
if let Ok(cmd) = process.command_line_with_buffer(&mut buffer) {
println!("{}: {}", proc_info.name, cmd);
}
}
}§Process tree operations
use windows_erg::process::{Process, ProcessId};
// Kill a process and all its children
let process = Process::open(ProcessId::new(1234))?;
process.kill_tree()?;
// Or kill entire tree from root ancestor
Process::kill_tree_from_root(ProcessId::new(1234))?;Re-exports§
Structs§
- Host
Memory Metrics - Point-in-time memory metrics for the host.
- Host
Metrics - Point-in-time metrics for the host.
- Memory
Info - Memory usage information.
- Module
Info - Module (DLL) information.
- Process
- A handle to a Windows process.
- Process
CpuTimes - Process CPU time counters.
- Process
Info - Basic process information.
- Process
Memory Metrics - Extended process memory metrics.
- Process
Metrics - Point-in-time metrics for a process.
- Process
Parameters - Process parameters from PEB.
- Process
Spawner - Builder for spawning processes with optional parent reparenting and token source.
- Spawned
Process - A spawned process with owned process/thread handles.
- Thread
Info - Thread information.
Enums§
- Process
Access - Process access rights.
Functions§
- host_
cpu_ usage - Calculate overall host CPU usage percentage over a sampling interval.
- host_
metrics - Get point-in-time host metrics.