windows_erg/registry/
mod.rs1mod builder;
66mod key;
67mod types;
68mod values;
69
70#[cfg(test)]
71mod tests;
72
73pub use builder::RegistryKeyBuilder;
74pub use key::RegistryKey;
75pub use types::{Access, Hive};
76pub use values::RegistryValue;
77
78use crate::Result;
79use crate::security::{ApplyMode, DescriptorEditResult, PermissionEditPlan, SecurityDescriptor};
80
81pub fn read_string(hive: Hive, path: &str, name: &str) -> Result<String> {
85 let key = RegistryKey::open(hive, path)?;
86 key.get_value(name)
87}
88
89pub fn write_string(hive: Hive, path: &str, name: &str, value: &str) -> Result<()> {
91 let key = RegistryKey::create(hive, path)?;
92 key.set_value(name, value.to_string())
93}
94
95pub fn read_u32(hive: Hive, path: &str, name: &str) -> Result<u32> {
97 let key = RegistryKey::open(hive, path)?;
98 key.get_value(name)
99}
100
101pub fn write_u32(hive: Hive, path: &str, name: &str, value: u32) -> Result<()> {
103 let key = RegistryKey::create(hive, path)?;
104 key.set_value(name, value)
105}
106
107pub fn read_u64(hive: Hive, path: &str, name: &str) -> Result<u64> {
109 let key = RegistryKey::open(hive, path)?;
110 key.get_value(name)
111}
112
113pub fn write_u64(hive: Hive, path: &str, name: &str, value: u64) -> Result<()> {
115 let key = RegistryKey::create(hive, path)?;
116 key.set_value(name, value)
117}
118
119pub fn read_bool(hive: Hive, path: &str, name: &str) -> Result<bool> {
121 let key = RegistryKey::open(hive, path)?;
122 key.get_value(name)
123}
124
125pub fn write_bool(hive: Hive, path: &str, name: &str, value: bool) -> Result<()> {
127 let key = RegistryKey::create(hive, path)?;
128 key.set_value(name, value)
129}
130
131pub fn read_binary(hive: Hive, path: &str, name: &str) -> Result<Vec<u8>> {
133 let key = RegistryKey::open(hive, path)?;
134 key.get_value(name)
135}
136
137pub fn write_binary(hive: Hive, path: &str, name: &str, value: &[u8]) -> Result<()> {
139 let key = RegistryKey::create(hive, path)?;
140 key.set_value(name, value.to_vec())
141}
142
143pub fn read_multi_string(hive: Hive, path: &str, name: &str) -> Result<Vec<String>> {
145 let key = RegistryKey::open(hive, path)?;
146 key.get_value(name)
147}
148
149pub fn write_multi_string(hive: Hive, path: &str, name: &str, value: &[String]) -> Result<()> {
151 let key = RegistryKey::create(hive, path)?;
152 key.set_value(name, value.to_vec())
153}
154
155pub fn read_security_descriptor(hive: Hive, path: &str) -> Result<SecurityDescriptor> {
157 let key = RegistryKey::open(hive, path)?;
158 key.security_descriptor()
159}
160
161pub fn write_security_descriptor(
163 hive: Hive,
164 path: &str,
165 descriptor: &SecurityDescriptor,
166) -> Result<()> {
167 let key = RegistryKey::builder()
168 .hive(hive)
169 .path(path)
170 .read_write()
171 .open()?;
172 key.set_security_descriptor(descriptor)
173}
174
175pub fn apply_permissions(
177 hive: Hive,
178 path: &str,
179 plan: &PermissionEditPlan,
180 mode: ApplyMode,
181) -> Result<DescriptorEditResult> {
182 let key = RegistryKey::builder()
183 .hive(hive)
184 .path(path)
185 .read_write()
186 .open()?;
187 key.apply_permissions(plan, mode)
188}