Debian Codegraph @

third_party/rust/winreg/examples/load_app_key.rs

raw
1 // Copyright 2021, Igor Shaula
2 // Licensed under the MIT License <LICENSE or
3 // http://opensource.org/licenses/MIT>. This file
4 // may not be copied, modified, or distributed
5 // except according to those terms.
6 extern crate winreg;
7 use std::io;
8 use winreg::enums::*;
9 use winreg::RegKey;
10
11 fn main() -> io::Result<()> {
12 {
13 // put this in a block so app_key_1 gets out of scope and doesn't prevent us
14 // from loading the key again later
15 let app_key_1 = RegKey::load_app_key("myhive.dat", true)?;
16 app_key_1.set_value("answer", &42u32)?;
17 }
18 let answer: u32 = {
19 // NOTE: on Windows 7 this fails with ERROR_ALREADY_EXISTS
20 let app_key_2 =
21 RegKey::load_app_key_with_flags("myhive.dat", KEY_READ, REG_PROCESS_APPKEY)?;
22 app_key_2.get_value("answer")?
23 };
24 println!("The Answer is {}", answer);
25 Ok(())
26 }