From 620e1f596f56956bd443fe91b6ec9404aa3f6493 Mon Sep 17 00:00:00 2001 From: Honsun Zhu Date: Wed, 14 Aug 2024 17:15:49 +0800 Subject: [PATCH] feat: use windows-registry replace winreg --- Cargo.toml | 2 +- src/machine_id.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ecd1279..f91f63a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ hostname = "^0.3" sysctl = "^0.4" [target.'cfg(target_os = "windows")'.dependencies] -winreg = "^0.8" +windows-registry = "^0.2" [dev-dependencies] criterion = "0.3" diff --git a/src/machine_id.rs b/src/machine_id.rs index ff5f5e6..5c4da52 100644 --- a/src/machine_id.rs +++ b/src/machine_id.rs @@ -54,10 +54,11 @@ fn machine_id() -> Result { // https://github.com/rs/xid/blob/efa678f304ab65d6d57eedcb086798381ae22206/hostid_windows.go #[cfg(target_os = "windows")] fn machine_id() -> std::io::Result { - let hklm = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE); - let guid: String = hklm - .open_subkey("SOFTWARE\\Microsoft\\Cryptography")? - .get_value("MachineGuid")?; + use windows_registry::*; + + let guid = LOCAL_MACHINE + .open("SOFTWARE\\Microsoft\\Cryptography")? + .get_string("MachineGuid")?; Ok(guid) }