-- Cargo.toml
[package]
name = "win_network_fixer"
version = "0.1.0"
edition = "2024"

[[bin]]
name = "r-winnat"
path = "./bin/restart-winnat.rs"

[[bin]]
name = "r-wslnat"
path = "./bin/restart-wsl-net.rs"


[dependencies]
runas = "1.2.0"

--\bin\restart-winnat.rs
fn main() {
    runas::Command::new("net")
        .args(&["stop", "winnat"])
        .gui(false)
        .force_prompt(false)
        .status()
        .expect("failed to execute");

    runas::Command::new("net")
        .args(&["start", "winnat"])
        .gui(false)
        .force_prompt(false)
        .status()
        .expect("failed to execute");

}

--\bin\restart-wsl-net.rs
fn main() {
    /*
    wsl --shutdown
        net stop hns
        net start hns
        */
    runas::Command::new("wsl")
        .args(&["--shutdown"])
        .gui(false)
        .force_prompt(false)
        .status()
        .expect("failed to execute");

    runas::Command::new("net")
        .args(&["stop", "hns"])
        .gui(false)
        .force_prompt(false)
        .status()
        .expect("failed to execute");
    runas::Command::new("net")
        .args(&["start", "hns"])
        .gui(false)
        .force_prompt(false)
        .status()
        .expect("failed to execute");
}

Изменить пасту