1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//! 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
//!
//! ```no_run
//! use windows_erg::process::{Process, ProcessId};
//!
//! # fn main() -> windows_erg::Result<()> {
//! let process = Process::open(ProcessId::new(1234))?;
//! println!("Process name: {}", process.name()?);
//! println!("Process path: {}", process.path()?.display());
//! # Ok(())
//! # }
//! ```
//!
//! ## Reading PEB data
//!
//! ```no_run
//! use windows_erg::process::Process;
//!
//! # fn main() -> windows_erg::Result<()> {
//! let process = Process::current();
//! println!("Command line: {}", process.command_line()?);
//!
//! let env = process.environment()?;
//! for (key, value) in env {
//! println!("{} = {}", key, value);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Listing all processes
//!
//! ```no_run
//! use windows_erg::process::Process;
//!
//! # fn main() -> windows_erg::Result<()> {
//! let processes = Process::list()?;
//! for proc in processes {
//! println!("{}: {}", proc.pid, proc.name);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Using buffer reuse for performance
//!
//! ```no_run
//! use windows_erg::process::Process;
//!
//! # fn main() -> windows_erg::Result<()> {
//! 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);
//! }
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Process tree operations
//!
//! ```no_run
//! use windows_erg::process::{Process, ProcessId};
//!
//! # fn main() -> windows_erg::Result<()> {
//! // 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))?;
//! # Ok(())
//! # }
//! ```
// Re-export public types
pub use Process;
pub use ;
pub use ;
pub use ;