+ 收藏我们

网站模板

网站模板搜索
404模板 营销型模板 外贸网站模板 单页模板 双语模板 标签大全
电话:18630701785
首页 > 站长学院 > rust延迟5秒锁屏的实现代码 >

rust延迟5秒锁屏的实现代码

时间:2024-04-15 09:55:08

先给大家介绍下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);

}
扩展知识:下面看下rust计算程序运行时间

main.rs
use std::thread::sleep;
use std::time::{Duration,Instant};
fn main() {
    let now = Instant::now();  // 程序起始时间
    println!("{:?}",now);  

    let three_seconds = Duration::from_secs(3);
    sleep(three_seconds);  // 延迟3秒

    let end = now.elapsed().as_secs();
    println!("程序运行了 {:?} 秒",end);     // 程序终止时间
}
到此这篇关于rust延迟5秒锁屏的实现代码的文章就介绍到这了,先给大家介绍下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);

}
扩展知识:下面看下rust计算程序运行时间

main.rs
use std::thread::sleep;
use std::time::{Duration,Instant};
fn main() {
    let now = Instant::now();  // 程序起始时间
    println!("{:?}",now);  

    let three_seconds = Duration::from_secs(3);
    sleep(three_seconds);  // 延迟3秒

    let end = now.elapsed().as_secs();
    println!("程序运行了 {:?} 秒",end);     // 程序终止时间
}
到此这篇关于rust延迟5秒锁屏的实现代码的文章就介绍到这了。

有问题可以加入网站技术QQ群一起交流学习

本站会员学习、解决问题QQ群(691961965)

客服微信号:lpf010888

pbootcms教程

织梦教程

站长学院

SEO

wordpress

竞价教程

信息流

源码购买

源码之家

小程序源码

源码论坛

源码分享

源码下载

Title