DEV Community

loading...

Retrieving MachineGuid on Windows in Rust

Vee Satayamas
Free software developer
・1 min read

10 เมษายน 2562

AFAIK Generating UUID and Xid needs the MachineGuid, so I looked around how to obtain it.

And this is the solution, which I'm not sure if it will work on every Windows machine. 😅

main.rs

use winreg::RegKey;
use winreg::enums::*;
use std::io;

fn main() -> io::Result<()> {
    let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
    let cur_ver = hklm.open_subkey("SOFTWARE\\Microsoft\\Cryptography")?;
    let guid: String = cur_ver.get_value("MachineGuid")?;
    println!("MachineGuid = {}", guid);
    Ok(())
}
Enter fullscreen mode Exit fullscreen mode

Cargo.toml

[package]
name = "mach_guid"
version = "0.1.0"
authors = ["veer6"]
edition = "2018"

[dependencies]
winreg = "0.6"
Enter fullscreen mode Exit fullscreen mode

Discussion (0)