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
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.
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()?;
pub fn QueryInfoKey(
self,
class: Option<&mut WString>,
num_sub_keys: Option<&mut u32>,
max_sub_key_name_len: Option<&mut u32>,
max_class_len: Option<&mut u32>,
num_values: Option<&mut u32>,
max_value_name_len: Option<&mut u32>,
max_value_len: Option<&mut u32>,
security_descr_len: Option<&mut u32>,
last_write_time: Option<&mut FILETIME>
) -> WinResult<()>
pub fn QueryInfoKey(
self,
class: Option<&mut WString>,
num_sub_keys: Option<&mut u32>,
max_sub_key_name_len: Option<&mut u32>,
max_class_len: Option<&mut u32>,
num_values: Option<&mut u32>,
max_value_name_len: Option<&mut u32>,
max_value_len: Option<&mut u32>,
security_descr_len: Option<&mut u32>,
last_write_time: Option<&mut FILETIME>
) -> WinResult<()>
RegQueryInfoKey
method.
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
Auto Trait Implementations
Blanket Implementations
Mutably borrows from an owned value. Read more