pub struct HKEY(/* private fields */);
advapi
only.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§
Source§impl HKEY
impl HKEY
Sourcepub const unsafe fn from_ptr(p: *mut c_void) -> Self
pub const unsafe fn from_ptr(p: *mut c_void) -> Self
Constructs a new handle object by wrapping a pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
Be sure the pointer has the correct type and isn’t owned by anyone else, otherwise you may cause memory access violations.
Sourcepub const unsafe fn raw_copy(&self) -> Self
pub const unsafe fn raw_copy(&self) -> Self
Returns a raw copy of the underlying handle pointer.
§Safety
As the name implies, raw_copy
returns a raw copy of the
handle, so closing one of the copies won’t close the others.
This means a handle can be used after it has been closed, what
can lead to errors and undefined behavior. Even worse: sometimes
Windows reuses handle values, so you can call a method on a
completely different handle type, what can be catastrophic.
However, in some cases the Windows API demands a copy of the
handle – raw_copy
is an escape hatch to fill this gap.
Sourcepub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
pub const unsafe fn as_mut(&mut self) -> &mut *mut c_void
Returns a mutable reference to the underlying raw pointer.
This method can be used as an escape hatch to interoperate with other libraries.
§Safety
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
Sourcepub const fn ptr(&self) -> *mut c_void
pub const fn ptr(&self) -> *mut c_void
Returns the underlying raw pointer.
This method exposes the raw pointer used by raw Windows calls. It’s an opaque pointer to an internal Windows structure, and no dereferencings should be attempted.
This method can be used as an escape hatch to interoperate with other libraries.
Source§impl HKEY
impl HKEY
Sourcepub const CLASSES_ROOT: HKEY
pub const CLASSES_ROOT: HKEY
Predefined registry key, always open.
Sourcepub const CURRENT_USER: HKEY
pub const CURRENT_USER: HKEY
Predefined registry key, always open.
Sourcepub const LOCAL_MACHINE: HKEY
pub const LOCAL_MACHINE: HKEY
Predefined registry key, always open.
Sourcepub const PERFORMANCE_DATA: HKEY
pub const PERFORMANCE_DATA: HKEY
Predefined registry key, always open.
Sourcepub const CURRENT_CONFIG: HKEY
pub const CURRENT_CONFIG: HKEY
Predefined registry key, always open.
Sourcepub const CURRENT_USER_LOCAL_SETTINGS: HKEY
pub const CURRENT_USER_LOCAL_SETTINGS: HKEY
Predefined registry key, always open.
Sourcepub const PERFORMANCE_TEXT: HKEY
pub const PERFORMANCE_TEXT: HKEY
Predefined registry key, always open.
Sourcepub const PERFORMANCE_NLSTEXT: HKEY
pub const PERFORMANCE_NLSTEXT: HKEY
Predefined registry key, always open.
Sourcepub fn RegConnectRegistry(
machine_name: Option<&str>,
predef_hkey: &HKEY,
) -> SysResult<RegCloseKeyGuard>
pub fn RegConnectRegistry( machine_name: Option<&str>, predef_hkey: &HKEY, ) -> SysResult<RegCloseKeyGuard>
Sourcepub fn RegCopyTree(&self, sub_key: Option<&str>, dest: &HKEY) -> SysResult<()>
pub fn RegCopyTree(&self, sub_key: Option<&str>, dest: &HKEY) -> SysResult<()>
RegCopyTree
function.
Sourcepub fn RegCreateKeyEx(
&self,
sub_key: &str,
class: Option<&str>,
options: REG_OPTION,
access_rights: KEY,
security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>,
) -> SysResult<(RegCloseKeyGuard, REG_DISPOSITION)>
pub fn RegCreateKeyEx( &self, sub_key: &str, class: Option<&str>, options: REG_OPTION, access_rights: KEY, security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>, ) -> SysResult<(RegCloseKeyGuard, REG_DISPOSITION)>
RegCreateKeyEx
function.
Sourcepub fn RegCreateKeyTransacted(
&self,
sub_key: &str,
class: Option<&str>,
options: REG_OPTION,
access_rights: KEY,
security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>,
htransaction: &HTRANSACTION,
) -> SysResult<(RegCloseKeyGuard, REG_DISPOSITION)>
pub fn RegCreateKeyTransacted( &self, sub_key: &str, class: Option<&str>, options: REG_OPTION, access_rights: KEY, security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>, htransaction: &HTRANSACTION, ) -> SysResult<(RegCloseKeyGuard, REG_DISPOSITION)>
RegCreateKeyTransacted
function.
Sourcepub fn RegDeleteKey(&self, sub_key: &str) -> SysResult<()>
pub fn RegDeleteKey(&self, sub_key: &str) -> SysResult<()>
RegDeleteKey
function.
Sourcepub fn RegDeleteKeyEx(&self, sub_key: &str, platform_view: KEY) -> SysResult<()>
pub fn RegDeleteKeyEx(&self, sub_key: &str, platform_view: KEY) -> SysResult<()>
RegDeleteKeyEx
function.
§Panics
Panics if platform_view
is different from
co::KEY::WOW64_32KEY
and
co::KEY::WOW64_64KEY
.
Sourcepub fn RegDeleteKeyTransacted(
&self,
sub_key: &str,
access_rights: KEY,
htransaction: &HTRANSACTION,
) -> SysResult<()>
pub fn RegDeleteKeyTransacted( &self, sub_key: &str, access_rights: KEY, htransaction: &HTRANSACTION, ) -> SysResult<()>
RegDeleteKeyTransacted
function.
Sourcepub fn RegDeleteTree(&self, sub_key: Option<&str>) -> SysResult<()>
pub fn RegDeleteTree(&self, sub_key: Option<&str>) -> SysResult<()>
RegDeleteTree
function.
Sourcepub fn RegDeleteValue(&self, value_name: Option<&str>) -> SysResult<()>
pub fn RegDeleteValue(&self, value_name: Option<&str>) -> SysResult<()>
RegDeleteValue
function.
Sourcepub fn RegDisableReflectionKey(&self) -> SysResult<()>
pub fn RegDisableReflectionKey(&self) -> SysResult<()>
RegDisableReflectionKey
function.
Sourcepub fn RegEnableReflectionKey(&self) -> SysResult<()>
pub fn RegEnableReflectionKey(&self) -> SysResult<()>
RegEnableReflectionKey
function.
Sourcepub fn RegEnumKeyEx(
&self,
) -> SysResult<impl DoubleEndedIterator<Item = SysResult<String>> + '_>
pub fn RegEnumKeyEx( &self, ) -> SysResult<impl DoubleEndedIterator<Item = SysResult<String>> + '_>
Returns an iterator over the names of the keys, which calls
RegEnumKeyEx
repeatedly.
§Examples
use winsafe::{self as w, prelude::*, co};
let hkey = w::HKEY::CURRENT_USER.RegOpenKeyEx(
Some("Control Panel"),
co::REG_OPTION::default(),
co::KEY::READ,
)?;
for key_name in hkey.RegEnumKeyEx()? {
let key_name = key_name?;
println!("{}", key_name);
}
// Collecting into a Vec
let names: Vec<String> =
hkey.RegEnumKeyEx()?
.collect::<w::SysResult<Vec<_>>>()?;
Sourcepub fn RegEnumValue(
&self,
) -> SysResult<impl DoubleEndedIterator<Item = SysResult<(String, REG)>> + '_>
pub fn RegEnumValue( &self, ) -> SysResult<impl DoubleEndedIterator<Item = SysResult<(String, REG)>> + '_>
Returns an iterator of the names and types of the values, which calls
RegEnumValue
repeatedly.
§Examples
use winsafe::{self as w, prelude::*, co};
let hkey = w::HKEY::CURRENT_USER.RegOpenKeyEx(
Some("Control Panel\\Appearance"),
co::REG_OPTION::default(),
co::KEY::READ,
)?;
for value_and_type in hkey.RegEnumValue()? {
let (value, reg_type) = value_and_type?;
println!("{}, {}", value, reg_type);
}
// Collecting into a Vec
let values_and_types: Vec<(String, co::REG)> =
hkey.RegEnumValue()?
.collect::<w::SysResult<Vec<_>>>()?;
Sourcepub fn RegFlushKey(&self) -> SysResult<()>
pub fn RegFlushKey(&self) -> SysResult<()>
RegFlushKey
function.
Sourcepub fn RegGetValue(
&self,
sub_key: Option<&str>,
value_name: Option<&str>,
flags: RRF,
) -> SysResult<RegistryValue>
pub fn RegGetValue( &self, sub_key: Option<&str>, value_name: Option<&str>, flags: RRF, ) -> SysResult<RegistryValue>
RegGetValue
function.
§Examples
use winsafe::{self as w, prelude::*, co};
let val = w::HKEY::CURRENT_USER.RegGetValue(
Some("Control Panel\\Mouse"),
Some("Beep"),
co::RRF::RT_ANY,
)?;
println!("{val}");
Sourcepub fn RegLoadKey(
&self,
sub_key: Option<&str>,
file_path: &str,
) -> SysResult<()>
pub fn RegLoadKey( &self, sub_key: Option<&str>, file_path: &str, ) -> SysResult<()>
RegLoadKey
function.
Sourcepub fn RegOpenCurrentUser(access_rights: KEY) -> SysResult<RegCloseKeyGuard>
pub fn RegOpenCurrentUser(access_rights: KEY) -> SysResult<RegCloseKeyGuard>
RegOpenCurrentUser
function.
Sourcepub fn RegOpenKeyEx(
&self,
sub_key: Option<&str>,
options: REG_OPTION,
access_rights: KEY,
) -> SysResult<RegCloseKeyGuard>
pub fn RegOpenKeyEx( &self, sub_key: Option<&str>, options: REG_OPTION, access_rights: KEY, ) -> SysResult<RegCloseKeyGuard>
RegOpenKeyEx
function.
§Examples
use winsafe::{self as w, prelude::*, co};
let hkey = w::HKEY::CURRENT_USER.RegOpenKeyEx(
Some("Control Panel\\Mouse"),
co::REG_OPTION::default(),
co::KEY::READ,
)?;
Sourcepub fn RegOpenKeyTransacted(
&self,
sub_key: &str,
options: REG_OPTION,
access_rights: KEY,
htransaction: &HTRANSACTION,
) -> SysResult<RegCloseKeyGuard>
pub fn RegOpenKeyTransacted( &self, sub_key: &str, options: REG_OPTION, access_rights: KEY, htransaction: &HTRANSACTION, ) -> SysResult<RegCloseKeyGuard>
RegOpenKeyTransacted
function.
Sourcepub fn RegQueryInfoKey(
&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>,
) -> SysResult<()>
pub fn RegQueryInfoKey( &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>, ) -> SysResult<()>
RegQueryInfoKey
function.
Sourcepub fn RegQueryMultipleValues(
&self,
value_names: &[impl AsRef<str>],
) -> SysResult<Vec<RegistryValue>>
pub fn RegQueryMultipleValues( &self, value_names: &[impl AsRef<str>], ) -> SysResult<Vec<RegistryValue>>
RegQueryMultipleValues
function.
§Examples
use winsafe::{self as w, prelude::*, co};
let hkey = w::HKEY::CURRENT_USER.RegOpenKeyEx(
Some("Control Panel\\Desktop"),
co::REG_OPTION::default(),
co::KEY::READ,
)?;
for val in hkey.RegQueryMultipleValues(&["DpiScalingVer", "WallPaper"])? {
println!("{val}");
}
Sourcepub fn RegQueryReflectionKey(&self) -> SysResult<bool>
pub fn RegQueryReflectionKey(&self) -> SysResult<bool>
RegQueryReflectionKey
function.
Sourcepub fn RegQueryValueEx(
&self,
value_name: Option<&str>,
) -> SysResult<RegistryValue>
pub fn RegQueryValueEx( &self, value_name: Option<&str>, ) -> SysResult<RegistryValue>
RegQueryValueEx
function.
§Examples
use winsafe::{self as w, prelude::*, co};
let hkey = w::HKEY::CURRENT_USER.RegOpenKeyEx(
Some("Control Panel\\Mouse"),
co::REG_OPTION::default(),
co::KEY::READ,
)?;
let val = hkey.RegQueryValueEx(Some("Beep"))?;
println!("{val}");
Sourcepub fn RegRenameKey(
&self,
sub_key_name: &str,
new_key_name: &str,
) -> SysResult<()>
pub fn RegRenameKey( &self, sub_key_name: &str, new_key_name: &str, ) -> SysResult<()>
RegRenameKey
function.
Sourcepub fn RegReplaceKey(
&self,
sub_key: Option<&str>,
new_src_file: &str,
old_file_backup: &str,
) -> SysResult<()>
pub fn RegReplaceKey( &self, sub_key: Option<&str>, new_src_file: &str, old_file_backup: &str, ) -> SysResult<()>
RegReplaceKey
function.
Sourcepub fn RegRestoreKey(
&self,
file_path: &str,
flags: REG_RESTORE,
) -> SysResult<()>
pub fn RegRestoreKey( &self, file_path: &str, flags: REG_RESTORE, ) -> SysResult<()>
RegRestoreKey
function.
Sourcepub fn RegSaveKey(
&self,
dest_file_path: &str,
security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>,
) -> SysResult<()>
pub fn RegSaveKey( &self, dest_file_path: &str, security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>, ) -> SysResult<()>
RegSaveKey
function.
Sourcepub fn RegSaveKeyEx(
&self,
dest_file_path: &str,
security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>,
flags: REG_SAVE,
) -> SysResult<()>
pub fn RegSaveKeyEx( &self, dest_file_path: &str, security_attributes: Option<&SECURITY_ATTRIBUTES<'_>>, flags: REG_SAVE, ) -> SysResult<()>
RegSaveKeyEx
function.
Sourcepub fn RegSetKeyValue(
&self,
sub_key: Option<&str>,
value_name: Option<&str>,
data: RegistryValue,
) -> SysResult<()>
pub fn RegSetKeyValue( &self, sub_key: Option<&str>, value_name: Option<&str>, data: RegistryValue, ) -> SysResult<()>
RegSetKeyValue
function.
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::{self as w, prelude::*};
w::HKEY::CURRENT_USER.RegSetKeyValue(
Some("Software\\My Company"),
Some("Color"),
w::RegistryValue::Sz("blue".to_owned()),
)?;
Sourcepub fn RegSetValueEx(
&self,
value_name: Option<&str>,
data: RegistryValue,
) -> SysResult<()>
pub fn RegSetValueEx( &self, value_name: Option<&str>, data: RegistryValue, ) -> SysResult<()>
RegSetValueEx
function.
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::{self as w, prelude::*, co};
let hkey = w::HKEY::CURRENT_USER.RegOpenKeyEx(
Some("Console\\Git Bash"),
co::REG_OPTION::default(),
co::KEY::ALL_ACCESS,
)?;
hkey.RegSetValueEx(
Some("Color"),
w::RegistryValue::Sz("blue".to_owned()),
)?;
Sourcepub fn RegUnLoadKey(&self, sub_key: Option<&str>) -> SysResult<()>
pub fn RegUnLoadKey(&self, sub_key: Option<&str>) -> SysResult<()>
RegUnLoadKey
function.
Trait Implementations§
Source§impl Handle for HKEY
impl Handle for HKEY
Source§const NULL: Self
const NULL: Self
kernel
only.0
.Source§const INVALID: Self
const INVALID: Self
kernel
only.-1
. Read moreSource§unsafe fn from_ptr(p: *mut c_void) -> Self
unsafe fn from_ptr(p: *mut c_void) -> Self
kernel
only.Source§unsafe fn raw_copy(&self) -> Self
unsafe fn raw_copy(&self) -> Self
kernel
only.Source§unsafe fn as_mut(&mut self) -> &mut *mut c_void
unsafe fn as_mut(&mut self) -> &mut *mut c_void
kernel
only.