pub struct RegistryKey { /* private fields */ }Expand description
A Windows Registry key with automatic handle management.
Implementations§
Source§impl RegistryKey
impl RegistryKey
Sourcepub fn builder() -> RegistryKeyBuilder
pub fn builder() -> RegistryKeyBuilder
Create a builder for opening a registry key with specific options.
§Examples
use windows_erg::registry::{Hive, RegistryKey};
let key = RegistryKey::builder()
.hive(Hive::LocalMachine)
.path(r"SOFTWARE\Microsoft")
.read()
.open()?;Sourcepub fn open(hive: Hive, subkey: &str) -> Result<Self>
pub fn open(hive: Hive, subkey: &str) -> Result<Self>
Open an existing registry key with read-only access.
§Examples
use windows_erg::registry::{Hive, RegistryKey};
let key = RegistryKey::open(
Hive::LocalMachine,
r"SOFTWARE\Microsoft\Windows\CurrentVersion"
)?;Sourcepub fn create(hive: Hive, subkey: &str) -> Result<Self>
pub fn create(hive: Hive, subkey: &str) -> Result<Self>
Create a new registry key or open it if it already exists.
§Examples
use windows_erg::registry::{Hive, RegistryKey};
let key = RegistryKey::create(Hive::CurrentUser, r"Software\MyApp")?;Sourcepub fn security_descriptor(&self) -> Result<SecurityDescriptor>
pub fn security_descriptor(&self) -> Result<SecurityDescriptor>
Read this key’s security descriptor through the security module.
Sourcepub fn set_security_descriptor(
&self,
descriptor: &SecurityDescriptor,
) -> Result<()>
pub fn set_security_descriptor( &self, descriptor: &SecurityDescriptor, ) -> Result<()>
Write a security descriptor to this key through the security module.
Sourcepub fn apply_permissions(
&self,
plan: &PermissionEditPlan,
mode: ApplyMode,
) -> Result<DescriptorEditResult>
pub fn apply_permissions( &self, plan: &PermissionEditPlan, mode: ApplyMode, ) -> Result<DescriptorEditResult>
Execute a planned permission edit against this key.
Sourcepub fn get_value<T: RegistryValue>(&self, name: &str) -> Result<T>
pub fn get_value<T: RegistryValue>(&self, name: &str) -> Result<T>
Get a typed value from the registry key.
§Examples
let value: String = key.get_value("SomeString")?;Sourcepub fn set_value<T: RegistryValue>(&self, name: &str, value: T) -> Result<()>
pub fn set_value<T: RegistryValue>(&self, name: &str, value: T) -> Result<()>
Set a typed value in the registry key.
§Examples
key.set_value("Version", "1.0.0")?;
key.set_value("Count", 42u32)?;Sourcepub fn delete_value(&self, name: &str) -> Result<()>
pub fn delete_value(&self, name: &str) -> Result<()>
Delete a value from the registry key.
Sourcepub fn value_exists(&self, name: &str) -> Result<bool>
pub fn value_exists(&self, name: &str) -> Result<bool>
Check if a value exists in the registry key.
§Examples
if key.value_exists("Version")? {
println!("Version exists");
}Sourcepub fn try_get_value<T: RegistryValue>(&self, name: &str) -> Option<T>
pub fn try_get_value<T: RegistryValue>(&self, name: &str) -> Option<T>
Try to get a value, returning None if it doesn’t exist.
§Examples
if let Some(version) = key.try_get_value::<String>("Version") {
println!("Version: {}", version);
}Sourcepub fn get_value_or<T: RegistryValue>(&self, name: &str, default: T) -> T
pub fn get_value_or<T: RegistryValue>(&self, name: &str, default: T) -> T
Get a value with a default if it doesn’t exist.
§Examples
let count = key.get_value_or("Count", 0u32);Sourcepub fn delete_key(hive: Hive, subkey: &str) -> Result<()>
pub fn delete_key(hive: Hive, subkey: &str) -> Result<()>
Delete a registry key.
Note: The key must not have any subkeys. Use delete_tree() to delete
a key and all its subkeys.
Sourcepub fn delete_tree(hive: Hive, subkey: &str) -> Result<()>
pub fn delete_tree(hive: Hive, subkey: &str) -> Result<()>
Delete a registry key and all its subkeys recursively.
Sourcepub fn value_names(&self) -> Result<Vec<String>>
pub fn value_names(&self) -> Result<Vec<String>>
Enumerate all value names in this key.