Spawning processes on Windows with Rust

0

I'm on Windows 10, and trying to spawn processes with std::process::Command. There are some apps that I want to open with Command::new("cmd"), and then pass in an argument. For example, I want to pass in start ms-settings:windowsupdate as well as start ms-settings:appsfeatures, which would open "Windows Update" and "Apps & Features" in "Windows Settings". However, as it stands, you cannot have more than one instance of "Windows Settings" open at a time. So, I want to open those specific processes one at a time, and when I close one process, I want the other one to spawn. The only way I've managed to do it is by doing:

let processes = [
    "start ms-settings:windowsupdate",
    "start ms-settings:appsfeatures"
]

for process in &processes {
    Command::new("cmd")
    .arg("/K")
    .arg(&process)
    .creation_flags(0x00000010) // CREATE_NEW_CONSOLE
    .status()
    .expect("Process could not be spawned.");
}

which works, but it will open a command prompt when the first process spawns, and the only way to spawn the next process is to close the command prompt that the first process opens (opposed to just closing the window itself). I've tried other flags in .creation_flags(), but the other flags will open all processes at once, so only the last start ms-settings: process will be opened, since there can't be more than one instance. Is there a way to spawn these processes one at a time, without having a command prompt also spawn?

windows
process
rust
asked on Stack Overflow Jun 16, 2019 by braycarlson

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0