Back to Windows Rs

Readme

crates/libs/registry/readme.md

731.2 KB
Original Source

Windows registry

The windows-registry crate provides simple, safe, and efficient access to the Windows registry.

Start by adding the following to your Cargo.toml file:

toml
[dependencies.windows-registry]
version = "0.6"

Read and write registry keys and values as needed:

rust,no_run
use windows_registry::*;

fn main() -> Result<()> {
    let key = CURRENT_USER.create(r"software\windows-rs")?;

    key.set_u32("number", 123)?;
    key.set_string("name", "Rust")?;

    println!("{}", key.get_u32("number")?);
    println!("{}", key.get_string("name")?);

    Ok(())
}

Use the options() method for even more control:

rust,no_run
use windows_registry::*;

fn main() -> Result<()> {
    let tx = Transaction::new()?;

    let key = CURRENT_USER
        .options()
        .read()
        .write()
        .create()
        .transaction(&tx)
        .open(r"software\windows-rs")?;

    key.set_u32("name", 123)?;

    tx.commit()?;

    Ok(())
}