diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/winreg/examples/basic_usage.rs | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/winreg/examples/basic_usage.rs')
-rw-r--r-- | third_party/rust/winreg/examples/basic_usage.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/third_party/rust/winreg/examples/basic_usage.rs b/third_party/rust/winreg/examples/basic_usage.rs new file mode 100644 index 0000000000..2a7a8c02d3 --- /dev/null +++ b/third_party/rust/winreg/examples/basic_usage.rs @@ -0,0 +1,50 @@ +// Copyright 2015, Igor Shaula +// Licensed under the MIT License <LICENSE or +// http://opensource.org/licenses/MIT>. This file +// may not be copied, modified, or distributed +// except according to those terms. +extern crate winreg; +use std::path::Path; +use std::io; +use winreg::RegKey; +use winreg::enums::*; + +fn main() { + println!("Reading some system info..."); + let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); + let cur_ver = hklm.open_subkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion").unwrap(); + let pf: String = cur_ver.get_value("ProgramFilesDir").unwrap(); + let dp: String = cur_ver.get_value("DevicePath").unwrap(); + println!("ProgramFiles = {}\nDevicePath = {}", pf, dp); + let info = cur_ver.query_info().unwrap(); + println!("info = {:?}", info); + + println!("And now lets write something..."); + let hkcu = RegKey::predef(HKEY_CURRENT_USER); + let path = Path::new("Software").join("WinregRsExample1"); + let key = hkcu.create_subkey(&path).unwrap(); + + key.set_value("TestSZ", &"written by Rust").unwrap(); + let sz_val: String = key.get_value("TestSZ").unwrap(); + key.delete_value("TestSZ").unwrap(); + println!("TestSZ = {}", sz_val); + + key.set_value("TestDWORD", &1234567890u32).unwrap(); + let dword_val: u32 = key.get_value("TestDWORD").unwrap(); + println!("TestDWORD = {}", dword_val); + + key.set_value("TestQWORD", &1234567891011121314u64).unwrap(); + let qword_val: u64 = key.get_value("TestQWORD").unwrap(); + println!("TestQWORD = {}", qword_val); + + key.create_subkey("sub\\key").unwrap(); + hkcu.delete_subkey_all(&path).unwrap(); + + println!("Trying to open nonexistent key..."); + hkcu.open_subkey(&path) + .unwrap_or_else(|e| match e.kind() { + io::ErrorKind::NotFound => panic!("Key doesn't exist"), + io::ErrorKind::PermissionDenied => panic!("Access denied"), + _ => panic!("{:?}", e) + }); +} |