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 std::collections::HashMap;
10 use std::fmt;
11 use winreg::enums::*;
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) => {
23 $s.as_ref().map(|x| &**x).unwrap_or("")
24 };
25 }
26
27 impl fmt::Display for InstalledApp {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 write!(
30 f,
31 "{}-{}",
32 str_from_opt!(self.DisplayName),
33 str_from_opt!(self.DisplayVersion)
34 )
35 }
36 }
37
main()38 fn main() {
39 let hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE);
40 let uninstall_key = hklm
41 .open_subkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")
42 .expect("key is missing");
43
44 let apps: HashMap<String, InstalledApp> =
45 uninstall_key.decode().expect("deserialization failed");
46
47 for v in apps.values() {
48 println!("{}", v);
49 }
50 }
51