rust-延迟5秒锁屏

180it 2023-03-11 PM 791℃ 0条

实例-rust-延迟5秒锁屏
main.rs

#![windows_subsystem = "windows"]
use std::process::Command;
use std::os::windows::process::CommandExt;
use std::thread::sleep;
use std::time::Duration;

fn main() {

    let time_seconds = Duration::from_secs(5);
    sleep(time_seconds); // 延迟5秒执行以下程序

    let output = if cfg!(target_os = "windows") {
        Command::new("cmd")
                .creation_flags(0x08000000)
                .arg("/C")
                .arg("Rundll32.exe user32.dll,LockWorkStation")
                .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);

}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

rust-延迟5秒锁屏