1 // Copyright 2017, 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 #[macro_use]
7 extern crate serde_derive;
8 extern crate winreg;
9 use winreg::enums::*;
10 use std::collections::HashMap;
11 use std::fmt;
12
13 #[allow(non_snake_case)]
14 #[derive(Debug, Serialize, Deserialize)]
15 struct InstalledApp {
16 DisplayName: Option<String>,
17 DisplayVersion: Option<String>,
18 UninstallString: Option<String>
19 }
20
21 macro_rules! str_from_opt {
22 ($s:expr) => { $s.as_ref().map(|x| &**x).unwrap_or("") }
23 }
24
25 impl fmt::Display for InstalledApp {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 write!(f, "{}-{}",
28 str_from_opt!(self.DisplayName),
29 str_from_opt!(self.DisplayVersion))
30 }
31 }
32
main()33 fn main() {
34 let hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE);
35 let uninstall_key = hklm.open_subkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")
36 .expect("key is missing");
37
38 let apps: HashMap<String, InstalledApp> = uninstall_key.decode().expect("deserialization failed");
39
40 for (_k, v) in &apps {
41 println!("{}", v);
42 }
43 }
44