#windows-registry #windows

bin+lib windows-env

Easily manage Windows environment variables permanently

3 unstable releases

0.2.0 Mar 26, 2025
0.1.1 Oct 13, 2024
0.1.0 Oct 12, 2024

#83 in Windows APIs

Download history 38/week @ 2024-12-11 162/week @ 2024-12-18 3/week @ 2024-12-25 14/week @ 2025-01-01 73/week @ 2025-01-08 191/week @ 2025-01-22 133/week @ 2025-01-29 4/week @ 2025-02-05 47/week @ 2025-02-12 17/week @ 2025-02-19 48/week @ 2025-02-26 37/week @ 2025-03-05 33/week @ 2025-03-12 136/week @ 2025-03-26

217 downloads per month
Used in bestool

MIT license

14KB
245 lines

windows-env

Easily manage Windows environment variables permanently, without the need to restart your system or terminal.

Features:

  • Easily operate list variables like PATH.

Note:

  • The env operation will affect the current terminal process since v0.2.0.

Installation

  • as lib:
    [target."cfg(windows)".dependencies]
    windows_env = "0.2.0"
    
  • as executable binary:
    cargo binstall windows-env        # see cargo-binstall: https://github.com/cargo-bins/cargo-binstall
    cargo install windows-env -F bin  # or compile from source manually
    

Example

  • binary usage: runs wenv -h to see help message.

  • lib usage:

    fn main() -> std::io::Result<()> {
        windows_env::set("TEST_ENV", "test")?;
        assert_eq!(windows_env::get("TEST_ENV")?.unwrap(), "test");
        windows_env::remove("TEST_ENV")?;
        assert!(windows_env::get("TEST_ENV")?.is_none());
    
        windows_env::append("TEST_ENV", "test1")?;
        windows_env::prepend("TEST_ENV", "test2")?;
        assert_eq!(windows_env::get("TEST_ENV")?.unwrap(), "test2;test1");
    
        windows_env::remove_from_list("TEST_ENV", "test2")?;
        assert!(windows_env::exists_in_list("TEST_ENV", "test1")?);
    
        windows_env::remove("TEST_ENV")?;
        Ok(())
    }
    

Compare

  • set_env:
    • it uses powershell script while this crate uses windows api

TODO

  • cli support
  • System env modification

MSRV

  • v0.1.1: 1.70

Dependencies

~132MB
~2M SLoC