怎么实现电脑10钟无操作自动关机? 怎么实现电脑10钟无操作自动关机? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用命令就可以了shutdown -s -t 600 using System;class Program{ static void Main() { shutdown(); } public static void shutdown() { System.Diagnostics.Process.Start("shutdown.exe","-s -t 0"); }} 或者 不用事件 用Timer 控制 触发 使用Timer控制时间。达到条件就关机。。 http://topic.csdn.net/t/20061211/11/5221453.html或者using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] struct LASTINPUTINFO { [MarshalAs(UnmanagedType.U4)] public int cbSize; [MarshalAs(UnmanagedType.U4)] public uint dwTime; } [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); //得到无操作时间 static long GetLastInputTime() { LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO(); vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo); if (!GetLastInputInfo(ref vLastInputInfo)) return 0; return Environment.TickCount - (long)vLastInputInfo.dwTime; } 然后用timer 检查 getlastinputtime 用定时器计时,然后创建进程调用cmd命令的shutdown就可以了 运行 里面 shutdown -s -t 600 600 就是10分钟 电脑里面开个作业 服务 到了点就调用 关闭电脑的 .dll我是这么理解的 话说要用全局钩子 监控消息 然后用计时 时间段内 无消息的话就调用 shutdown -s -t具体钩子监控 你看15L那个就好了..这个原理 和屏保是一样一样的..using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Mouse_Move { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private int tick=0; protected override void WndProc(ref Message msg) { base.WndProc(ref msg); tick=Environment.TickCount; } private void timer1_Tick(object sender, EventArgs e) { if(Environment.TickCount-tick> 2000) this.Close(); } } } System.Diagnostics.Process.Start("shutdown.exe","-s -t 0"); shutdown -f -s -t 600shutdown -a // cancel 1、使用全局钩子 监控 Keyboard Mouse 动作。2、注册一个Windows Service在要监视的机器,使用Timer 发现过了规定Time 使用 dos 命令或者别的方法都可以 关闭机器。 嗯,这个可以用全局的钩子监听键盘和鼠标的消息,触发的就采用timer去把机器关了 根据汉字得拼音的程序,在本机运行没问题,到服务器上报错 DataGridView控件增么增加统计行? 请问各位,如何获取光标前字符的个数 关于数码管显示时钟的程序 够朋友的进来一缆!! Remoting高手请进,一个问题好头痛哦!请大家帮我看看吧。我想这个问题是个很高深的东东!!!!!!!!!! 父窗体中多个子窗体,如何实现单独的关闭 数据连接字符串到底哪里出错 通配符*在正则表达式中怎么表示同样的效果 问一个简单的问题,得到解答就送分:)在线等~~~~~~~ c#发送html邮件问题。 关于 UDP打洞~~
{
static void Main()
{
shutdown();
}
public static void shutdown()
{
System.Diagnostics.Process.Start("shutdown.exe","-s -t 0");
}
}
达到条件就关机。。
或者using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)]
struct LASTINPUTINFO
{
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}
[DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
//得到无操作时间
static long GetLastInputTime()
{
LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
return Environment.TickCount - (long)vLastInputInfo.dwTime;
} 然后用timer 检查 getlastinputtime
我是这么理解的
具体钩子监控 你看15L那个就好了..
这个原理 和屏保是一样一样的..using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms; namespace Mouse_Move
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private int tick=0; protected override void WndProc(ref Message msg)
{
base.WndProc(ref msg);
tick=Environment.TickCount;
} private void timer1_Tick(object sender, EventArgs e)
{
if(Environment.TickCount-tick> 2000) this.Close();
}
}
}
shutdown -a // cancel
2、注册一个Windows Service在要监视的机器,使用Timer 发现过了规定Time 使用 dos 命令或者别的方法都可以 关闭机器。