using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1_Mzz
{
public partial class Form1 : Form
{
int count = 0;
int cishu = 3;
string[] setstr=new string[3] {"Matt", "shutdown", "Robert"};
string[] settime= new string[3] { "23", "20", "Robert" };
//
[DllImport("user32.dll")]
public static extern int MessageBeep(uint uType);
uint beepI = 0x00000030;
//
public Form1()
{
InitializeComponent();
settime = ReadTXT_ReadAllLines("time.txt");
}
private void Form1_Load(object sender, EventArgs e)
{
setstr = ReadTXT_ReadAllLines("set.txt");
this.Visible = false;
// if(this.WindowState == FormWindowState.Minimized) //判断是否最小化
{
this.ShowInTaskbar = false; //不显示在系统任务栏
notifyIcon1.Visible = true; //托盘图标可见
}
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
string stime = DateTime.Now.ToLongTimeString().ToString();
Console.WriteLine(DateTime.Now.Minute);
if (DateTime.Now.Minute%27== 0)
{
//到达指定时间自动注销用户
count = 1;
MessageBeep(beepI);
if (settime.Length > 0)
{
//MessageBox.Show("即将注销电脑!");
//System.Windows.Forms.MessageBox.Show(setstr[0] + "-11234", "消息提示:" + stime, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification, false);
if (DateTime.Now.Hour > Convert.ToInt32(settime[0]))
{
zhuxiao(1);
}
}
else
{
//MessageBox.Show("没有读到了");
if (DateTime.Now.Hour > 22)
{
zhuxiao(0);
}
}
}
//if ((DateTime.Now.Second %15==3))
if ((DateTime.Now.Minute %25 == 1)&&(DateTime.Now.Second>=55))
{
string spicname= DateTime.Now.ToString("hhmmss");
string datestr=DateTime.Now.ToString("yyyyMMdd");
Bitmap bmp = GetScreenCapture();
string WantedPath = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf(@"\"));
bmp.Save(WantedPath + datestr + spicname + ".jpg");
}
if ((count < cishu)&&count <10)
{
count++;
if (settime.Length > 1)
{
cishu = Convert.ToInt32(settime[1]);
}
System.Windows.Forms.MessageBox.Show(setstr[0] + "-同学友情提示", "消息提示:" + stime, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification, false);
//MessageBox.Show(stime+" 准备休息一下了", setstr[0]+"-同学友情提示");
}
}
private Bitmap GetScreenCapture()
{
Rectangle tScreenRect = new Rectangle(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Bitmap tSrcBmp = new Bitmap(tScreenRect.Width, tScreenRect.Height); // 用于屏幕原始图片保存
Graphics gp = Graphics.FromImage(tSrcBmp);
gp.CopyFromScreen(0, 0, 0, 0, tScreenRect.Size);
gp.DrawImage(tSrcBmp, 0, 0, tScreenRect, GraphicsUnit.Pixel);
return tSrcBmp;
}
public static string[] ReadTXT_ReadAllLines(string pathAName)
{
string[] txtContent = null;
txtContent = System.IO.File.ReadAllLines(pathAName, Encoding.UTF8);
return txtContent;
}
public static void zhuxiao(int keytp)
{
System.Windows.Forms.MessageBox.Show( "-友情提示", "消息提示:即将关机" , MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification, false);
// 创建ProcessStartInfo对象
ProcessStartInfo startInfo = new ProcessStartInfo();
// 设置FileName为cmd.exe,表示要执行的是命令提示符
startInfo.FileName = "cmd.exe";
if (keytp == 0)
// 设置Arguments为要执行的命令,这里使用/c参数来执行命令后关闭CMD窗口
startInfo.Arguments = "/c shutdown -l";
if (keytp == 1)
startInfo.Arguments = "/c shutdown /s";
// 设置UseShellExecute为false,这样我们就可以重定向输出
startInfo.UseShellExecute = false;
// 设置RedirectStandardOutput为true,这样我们就可以读取输出
startInfo.RedirectStandardOutput = true;
// 创建Process对象并启动
using (Process process = Process.Start(startInfo))
{
// 等待进程完成
process.WaitForExit();
// 读取输出信息
string output = process.StandardOutput.ReadToEnd();
// 打印输出信息
Console.WriteLine(output);
}
}
}
}
功能实现定时弹提示,到点晚上默认22点强制关机,可以用批处理文件启动程序,并将批处理文件放到windows定时任务中