2 releases
Uses old Rust 2015
0.1.1 | Aug 30, 2019 |
---|---|
0.1.0 | Jul 22, 2018 |
#227 in Windows APIs
13KB
207 lines
reg-watcher
Rust binding to MS Windows RegNotifyChangeKeyValue
API.
Features
- synchronous and asynchronous API for registry change watching
- Tokio stream API
Usage
[dependencies]
reg-watcher = "0.1"
Basic usage
extern crate reg_watcher;
extern crate winreg;
use winreg::{
RegKey,
enums::*,
};
use reg_watcher::*;
fn main() {
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let reg_key = hklm.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"#).unwrap();
let res = watch(®_key, filter::REG_LEGAL_CHANGE_FILTER, true, Timeout::Milli(60 * 1000)).unwrap();
println!("{:?}", res);
}
Async
extern crate reg_watcher;
extern crate winreg;
use std::{
time::Duration,
sync::mpsc::channel,
};
use winreg::{
RegKey,
enums::*,
};
use reg_watcher::*;
fn main() {
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let reg_key = hklm.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"#).unwrap();
let mut w = Watcher::new(reg_key, filter::REG_LEGAL_CHANGE_FILTER, true, Duration::from_secs(1));
let (sender, receiver) = channel();
let _ = w.watch_async(sender);
loop {
let res = receiver.recv().unwrap();
println!("{:?}", res);
}
}
Stream
extern crate futures;
extern crate reg_watcher;
extern crate winreg;
extern crate tokio;
use futures::prelude::*;
use std::{
time::Duration,
};
use winreg::{
RegKey,
enums::*,
};
use reg_watcher::*;
fn main() {
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let reg_key = hklm.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"#).unwrap();
let w = Watcher::new(reg_key, filter::REG_LEGAL_CHANGE_FILTER, true, Duration::from_secs(1));
let fut = w.for_each(|_| {
println!("notify");
Ok(())
}).map_err(|err| {
println!("accept error = {:?}", err);
});
tokio::run(fut);
}
Dependencies
~5MB
~69K SLoC