Board logo

标题: [文件操作] 请教WIN10下能用的批处理系统空闲时间监测 [打印本页]

作者: conan2095    时间: 2021-12-22 19:53     标题: 请教WIN10下能用的批处理系统空闲时间监测

在WIN10 下 鼠标键盘多久时间没动 就执行程序,比如说自动关机。
论坛里面搜出来的几个WIN10 下好像都不能执行。
作者: Batcher    时间: 2021-12-22 21:31

回复 1# conan2095


    你搜到的是哪几个?我试试能否修改成Win10能用的。
作者: conan2095    时间: 2021-12-22 21:44

回复 2# Batcher


    http://www.bathome.net/thread-20370-1-1.html

大哥是这个帖子
作者: idwma    时间: 2021-12-23 16:25

  1. #@&cls&powershell "type %~s0|out-string|iex"&pause&exit
  2. Add-Type @'
  3. using System;
  4. using System.Runtime.InteropServices;
  5. public static class GetIdleTime {
  6.     [DllImport("user32.dll")]
  7.     public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
  8.     [StructLayout(LayoutKind.Sequential)]
  9.     public struct LASTINPUTINFO {
  10.         public int cbSize;
  11.         public uint dwTime;
  12.     }
  13.     public static long IdleTime{
  14.         get {
  15.             LASTINPUTINFO lii = new LASTINPUTINFO();
  16.             lii.cbSize = Marshal.SizeOf(lii);
  17.             if (!GetLastInputInfo(ref lii)) return 0;
  18.             return Environment.TickCount - (uint)lii.dwTime;
  19.         }
  20.     }
  21. }
  22. '@
  23. while(!(sleep 1)){
  24.     if([getidletime]::IdleTime/1000 -gt 3){"空闲时间大于3秒"}
  25. }
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2