Skip to content

Instantly share code, notes, and snippets.

@puppis42
Created May 27, 2023 23:50
Show Gist options
  • Save puppis42/9d7d652f14180c0cb1e6ba1d8be2bc5a to your computer and use it in GitHub Desktop.
Save puppis42/9d7d652f14180c0cb1e6ba1d8be2bc5a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DetectShutdown
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static int WM_QUERYENDSESSION = 0x11;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
File.WriteAllText(@"C:\Users\uname\Desktop\success.txt", "SUCESS");
Environment.Exit(0);
}
else
{
label1.Text = "Nothing happends for now.";
}
base.WndProc(ref m);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment