File tree Expand file tree Collapse file tree 4 files changed +35
-2
lines changed
tests/libs/registry/tests Expand file tree Collapse file tree 4 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ pub const REG_EXPAND_SZ: REG_VALUE_TYPE = 2u32;
7272pub const REG_MULTI_SZ : REG_VALUE_TYPE = 7u32 ;
7373pub type REG_OPEN_CREATE_OPTIONS = u32 ;
7474pub const REG_OPTION_NON_VOLATILE : REG_OPEN_CREATE_OPTIONS = 0u32 ;
75+ pub const REG_OPTION_VOLATILE : REG_OPEN_CREATE_OPTIONS = 1u32 ;
7576pub const REG_QWORD : REG_VALUE_TYPE = 11u32 ;
7677pub type REG_SAM_FLAGS = u32 ;
7778pub const REG_SZ : REG_VALUE_TYPE = 1u32 ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub struct OpenOptions<'a> {
77 access : u32 ,
88 create : bool ,
99 transaction : Option < & ' a Transaction > ,
10+ options : u32 ,
1011}
1112
1213impl < ' a > OpenOptions < ' a > {
@@ -16,6 +17,7 @@ impl<'a> OpenOptions<'a> {
1617 access : 0 ,
1718 create : false ,
1819 transaction : None ,
20+ options : REG_OPTION_NON_VOLATILE ,
1921 }
2022 }
2123
@@ -49,6 +51,12 @@ impl<'a> OpenOptions<'a> {
4951 self
5052 }
5153
54+ /// Sets the option to create a volatile registry key that is not preserved when the system restarts.
55+ pub fn volatile ( & mut self ) -> & mut Self {
56+ self . options |= REG_OPTION_VOLATILE ;
57+ self
58+ }
59+
5260 /// Opens a registry key with the options provided by `self`.
5361 pub fn open < T : AsRef < str > > ( & self , path : T ) -> Result < Key > {
5462 let mut handle = null_mut ( ) ;
@@ -61,7 +69,7 @@ impl<'a> OpenOptions<'a> {
6169 pcwstr ( path) . as_ptr ( ) ,
6270 0 ,
6371 null ( ) ,
64- REG_OPTION_NON_VOLATILE ,
72+ self . options ,
6573 self . access ,
6674 null ( ) ,
6775 & mut handle,
@@ -86,7 +94,7 @@ impl<'a> OpenOptions<'a> {
8694 pcwstr ( path) . as_ptr ( ) ,
8795 0 ,
8896 null ( ) ,
89- REG_OPTION_NON_VOLATILE ,
97+ self . options ,
9098 self . access ,
9199 null ( ) ,
92100 & mut handle,
Original file line number Diff line number Diff line change 1+ use windows_registry:: * ;
2+
3+ #[ test]
4+ fn volatile_key ( ) {
5+ let test_key = "software\\ windows-rs\\ tests\\ volatile" ;
6+ _ = CURRENT_USER . remove_tree ( test_key) ;
7+
8+ // Create a volatile key - this key will not persist when the system restarts
9+ let key = CURRENT_USER
10+ . options ( )
11+ . create ( )
12+ . volatile ( )
13+ . read ( )
14+ . write ( )
15+ . open ( test_key)
16+ . unwrap ( ) ;
17+
18+ // Write some data to the volatile key
19+ key. set_u64 ( "test_value" , 12345u64 ) . unwrap ( ) ;
20+
21+ // Verify we can read the data
22+ assert_eq ! ( key. get_u64( "test_value" ) . unwrap( ) , 12345u64 ) ;
23+ }
Original file line number Diff line number Diff line change 2424 REG_EXPAND_SZ
2525 REG_MULTI_SZ
2626 REG_OPTION_NON_VOLATILE
27+ REG_OPTION_VOLATILE
2728 REG_QWORD
2829 REG_SZ
2930 RegCloseKey
You can’t perform that action at this time.
0 commit comments