Skip to main content

RegistryKey

Struct RegistryKey 

Source
pub struct RegistryKey { /* private fields */ }
Expand description

A Windows Registry key with automatic handle management.

Implementations§

Source§

impl RegistryKey

Source

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()?;
Source

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"
)?;
Source

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")?;
Source

pub fn security_descriptor(&self) -> Result<SecurityDescriptor>

Read this key’s security descriptor through the security module.

Source

pub fn set_security_descriptor( &self, descriptor: &SecurityDescriptor, ) -> Result<()>

Write a security descriptor to this key through the security module.

Source

pub fn apply_permissions( &self, plan: &PermissionEditPlan, mode: ApplyMode, ) -> Result<DescriptorEditResult>

Execute a planned permission edit against this key.

Source

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")?;
Source

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)?;
Source

pub fn delete_value(&self, name: &str) -> Result<()>

Delete a value from the registry key.

Source

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");
}
Source

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);
}
Source

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);
Source

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.

Source

pub fn delete_tree(hive: Hive, subkey: &str) -> Result<()>

Delete a registry key and all its subkeys recursively.

Source

pub fn subkeys(&self) -> Result<Vec<String>>

Enumerate all subkeys of this key.

Source

pub fn value_names(&self) -> Result<Vec<String>>

Enumerate all value names in this key.

Trait Implementations§

Source§

impl Drop for RegistryKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.