首页 > 其他分享 >rust执行cmd命令隐藏窗口

rust执行cmd命令隐藏窗口

时间:2022-09-18 20:45:33浏览次数:105  
标签:creation windows cmd process flags arg output 隐藏 rust

https://blog.csdn.net/weixin_35894173/article/details/112282032

https://rustcc.cn/article?id=f1630b61-4637-4e80-8414-8a921af50d68

主要原理是,通过函数creation_flags设置CreateProcess函数的creation flags,设置为 隐藏窗口即可。

关键命令:

#![windows_subsystem = "windows"]
use std::os::windows::process::CommandExt;

.creation_flags(0x08000000)
#![windows_subsystem = "windows"]
use std::process::Command;
use std::os::windows::process::CommandExt;

fn main() {

    let output = if cfg!(target_os = "windows") {
        Command::new("cmd")
                .creation_flags(0x08000000)
                .arg("/C")
                .arg("rundll32 sysdm.cpl,EditEnvironmentVariables")
                .output()
                .expect("failed to execute process")
    } else {
        Command::new("sh")
                .arg("-c")
                .arg("echo hello")
                .output()
                .expect("failed to execute process")
    };
    
    let hello = output.stdout;
    println!("{:?}", hello)
}

标签:creation,windows,cmd,process,flags,arg,output,隐藏,rust
From: https://www.cnblogs.com/Nazorine/p/16705694.html

相关文章

  • 实例-rust-打开计算器
    https://rust.ffactory.org/std/process/struct.Command.html进程生成器,提供对如何生成新进程的细粒度控制。可以使用Command::new(program)生成默认配置,其中program......
  • 实例-rust-打开环境变量
    main.rsusestd::process::Command;fnmain(){letoutput=ifcfg!(target_os="windows"){Command::new("cmd").arg("/C")......
  • rust
    https://juejin.cn/post/6844903821307723789externcrate关键字用于导入依赖库,你只需将其添加到主文件中,应用程序的任何源文件就都可以引用它了。use部分则是指你将在......
  • cmd 命令
    CMD常用命令打开cmd方式windowsexplorer地址栏在最前面直接添加cmd加空格即可在文件夹内按shift+鼠标右键,打开powerShell切换盘符英文路径加英文冒号切换目......
  • Rust 学习笔记
    学习资料rust程序语言英文:https://doc.rust-lang.org/book/title-page.html中文:https://kaisery.gitbooks.io/trpl-zh-cn/content/ch02-00-guessing-game-tutorial.ht......
  • cmd 'node' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    报错:cmd提示:‘node‘不是内部或外部命令,也不是可运行的程序原因:没安装node.js或者没配置好环境变量情况1:安装node.js下载地址:https://nodejs.org/en/安装步骤:默......
  • 实例-rust-将数据写入json文件
    Cargo.toml[package]name="rust-example5"version="0.1.0"edition="2021"#Seemorekeysandtheirdefinitionsathttps://doc.rust-lang.org/cargo/refere......
  • 实例-rust-string和bytes转换
    Cargo.toml[package]name="rust-example9"version="0.1.0"edition="2021"#Seemorekeysandtheirdefinitionsathttps://doc.rust-lang.org/cargo/refere......
  • 实例-rust-将struct写入json文件
    cargo.toml[package]name="rust-example5"version="0.1.0"edition="2021"#Seemorekeysandtheirdefinitionsathttps://doc.rust-lang.org/cargo/refere......
  • 实例-rust-从json文件中读取数据并将输出写入json文件
    Cargo.toml[package]name="rust-example5"version="0.1.0"edition="2021"#Seemorekeysandtheirdefinitionsathttps://doc.rust-lang.org/cargo/refere......