DEV Community

Vee Satayamas
Vee Satayamas

Posted on


Retrieving MachineGuid on Windows in Rust

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. 😅

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);
Enter fullscreen mode Exit fullscreen mode


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

winreg = "0.6"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)