Form1.cs
上传用户:tomsong001
上传日期:2022-03-19
资源大小:31k
文件大小:2k
源码类别:

钩子与API截获

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. namespace AutoShutdown
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         DateTime t;
  19.         private void btShutdown_Click(object sender, EventArgs e)
  20.         {
  21.             TimeSpan tp;
  22.             TimeSpan.TryParse(textTime.Text, out tp);
  23.             this.Text = tp.ToString();
  24.             t = DateTime.Now + tp;
  25.             timer1.Enabled = true;
  26.         }
  27.         private void Form1_Load(object sender, EventArgs e)
  28.         {
  29.             textTime.Text = "00:50:00";
  30.         }
  31.         internal const int EWX_SHUTDOWN = 0x00000001;
  32.         internal const int EWX_REBOOT = 0x00000002;
  33.         internal const int EWX_FORCE = 0x00000004;
  34.         [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
  35.         internal static extern bool ExitWindowsEx(int flg, int rea);
  36.         private void timer1_Tick(object sender, EventArgs e)
  37.         {
  38.             if (t> DateTime.Now)
  39.             {
  40.                 TimeSpan dt = t - DateTime.Now;
  41.                 this.label1.Text = (dt).ToString();
  42.             }
  43.             else
  44.             {
  45.                 timer1.Enabled = false;
  46.                 WindowsExit.PowerOff();
  47.                 this.label1.Text = "";
  48.             }
  49.         }
  50.     }
  51. }