Struct winsafe::HKEY[][src]

#[repr(C)]
pub struct HKEY { /* fields omitted */ }
Expand description

Handle to a registry key.

This handle also exposes several predefined registry keys, like HKEY::CURRENT_USER, which are always open and ready to be used. Usually, they are the starting point to open a registry key.

Implementations

The null, invalid handle.

This constant is common to all handle types.

Creates a new handle instance by wrapping a pointer.

This method is common to all handle types.

Consumes the handle returning the underlying raw pointer.

This method is common to all handle types.

Tells if the handle is invalid (null).

This method is common to all handle types.

Consumes the handle into an option, which is None if the handle pointer is null.

This method is common to all handle types.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

Predefined registry key, always open.

RegCloseKey method.

This method calls RegEnumKeyEx method repeatedly to retrieve all key names.

Examples

use winsafe::{co, HKEY};

let hkey = HKEY::CURRENT_USER.OpenKeyEx(
    "Control Panel",
    co::REG_OPTION::default(),
    co::KEY::READ,
)?;

let key_names = hkey.EnumKeyEx()?;
for key_name in key_names.iter() {
    println!("{}", key_name);
}

hkey.CloseKey()?;

This method calls RegEnumValue method repeatedly to retrieve all value names and types.

Examples

use winsafe::{co, HKEY};

let hkey = HKEY::CURRENT_USER.OpenKeyEx(
    "Control Panel\\Appearance",
    co::REG_OPTION::default(),
    co::KEY::READ,
)?;

let values_and_types = hkey.EnumValue()?;
for (value, reg_type) in values_and_types.iter() {
    println!("{}, {}", value, reg_type);
}

hkey.CloseKey()?;

RegGetValue method.

The data type will be automatically queried with a first call to RegGetValue.

Examples

use winsafe::{HKEY, RegistryValue};

let val = HKEY::CURRENT_USER.GetValue(
    "Control Panel\\Mouse",
    "Beep",
)?;

match val {
    RegistryValue::Dword(n) => println!("Number u32: {}", n),
    RegistryValue::Qword(n) => println!("Number u64: {}", n),
    RegistryValue::Sz(str) => println!("String: {}", str),
    RegistryValue::Binary(bin) => {
        println!("Binary:");
        for b in bin.iter() {
            print!("{:02x} ", b);
        }
        println!("");
    },
    RegistryValue::None => println!("No value"),
}

RegOpenKeyEx method.

Note: Must be paired with an HKEY::CloseKey call.

Examples

use winsafe::{co, HKEY};

let hkey = HKEY::CURRENT_USER.OpenKeyEx(
    "Control Panel\\Mouse",
    co::REG_OPTION::default(),
    co::KEY::READ,
)?;

hkey.CloseKey()?;

RegQueryValueEx method.

The data type will be automatically queried with a first call to RegQueryValueEx.

Examples

use winsafe::{co, HKEY, RegistryValue};

let hkey = HKEY::CURRENT_USER.OpenKeyEx(
    "Control Panel\\Mouse",
    co::REG_OPTION::default(),
    co::KEY::READ,
)?;

let val = hkey.QueryValueEx("Beep")?;

match val {
    RegistryValue::Dword(n) => println!("Number u32: {}", n),
    RegistryValue::Qword(n) => println!("Number u64: {}", n),
    RegistryValue::Sz(str) => println!("String: {}", str),
    RegistryValue::Binary(bin) => {
        println!("Binary:");
        for b in bin.iter() {
            print!("{:02x} ", b);
        }
        println!("");
    },
    RegistryValue::None => println!("No value"),
}

hkey.CloseKey()?;

RegSetKeyValue method.

If the value doesn’t exist, if will be created. If new type is different from current type, new type will take over.

Examples

use winsafe::{HKEY, RegistryValue};

HKEY::CURRENT_USER.SetKeyValue(
    "Software\\My Company",
    "Color",
    RegistryValue::Sz("blue".to_owned()),
)?;

RegSetValueEx method.

If the value doesn’t exist, if will be created. If new type is different from current type, new type will prevail.

Examples

use winsafe::{co, HKEY, RegistryValue};

let hkey = HKEY::CURRENT_USER.OpenKeyEx(
    "Console\\Git Bash",
    co::REG_OPTION::default(),
    co::KEY::ALL_ACCESS,
)?;

hkey.SetValueEx(
    "Color",
    RegistryValue::Sz("blue".to_owned()),
)?;

hkey.CloseKey()?;

Trait Implementations

Formats the value using the given formatter.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter.

Formats the value using the given formatter.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Formats the value using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.