Reading registry key value EnableLUA

Hi, I'm complete newbie to Rust, so please be patient :slight_smile:
I'm trying to read registry key value and it fails even when I run app as an Administrator. My code:

extern crate winreg;

use winreg::enums::{HKEY_LOCAL_MACHINE, KEY_READ};

fn main() {
  let hklm = winreg::RegKey::predef(HKEY_LOCAL_MACHINE);
  let subkey = hklm
      .open_subkey_with_flags(
          r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"#,
          KEY_READ,
      )
      .expect("Failed to open subkey");
  let u_uac_status: String = subkey.get_value("EnableLUA").expect("Failed to read");
  let mut r_uac_status: String = String::new();
  if u_uac_status == "1" {
      r_uac_status = String::from("Enable");
  } else {
      r_uac_status = String::from("Disable");
  }
  println!("UAC status: {}", r_uac_status);
}

The error:
thread 'main' panicked at 'Failed to read: Os { code: 222, kind: Other, message: "The file type being saved or retrieved has been blocked." }', libcore\result.rs:1009:5
note: Run with RUST_BACKTRACE=1 for a backtrace.
error: process didn't exit successfully (exit code: 101)

I tried to set RUST_BACKTRACE = 1 then cargo run, but it pops the same.
Thanks

This happens if the value type is not one of the defined registry value types lib.rs.html -- source I don't know why you'd see that happening though.

https://stackoverflow.com/questions/53849336/reading-registry-key-value-enablelua-error

yes, you my friend caused with your complaints that SO block me from asking questions, and I really do not feel that your arguments were justified especially because I try really hard to find answer before asking one... so I asked my friend to ask second question on my behalf.... I saw that you gave answer regarding antivirus, but that is not the cause of my problems

Hi Toma,
First off all, I posted the link so somebody who sees this question also can see the one on stackoverflow.
Second, you won't get banned of stackoverflow because of one question...
I think jethrogb is on the right track through.

Guy from SO helped me with this. His answer:

You're trying to read a String , but the registry contains an integer value. Try with:

let r_uac_status = subkey.get_value::<u32, _>("EnableLUA")
   .map (|u_uac_status|
         if u_uac_status == 1 { "Enable" } else { "Disable" })
   .expect("Failed to read");

Note: you don't even need administrator rights to read the value.