Aug 15, 2015

C# Detecting Windows Shutdown.

Ahhh ninggalin kerjaan semalem ini. Gegara Google semalem gak isa di akses akhirnya terpaksa beralih menggunakan Bing dan jebul ndak ketemu caranya. Pagi ini Google sudah bisa diakses kembali dan akhirnya ketemu caranya untuk mendeteksi Windows Shutdown atau Restart dengan menggunakan C#
Berikut kodenya
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Shutdown
{
    public partial class Form1 : Form
    {
        private static int WM_QUERYENDSESSION = 0x11;
        private static bool systemShutdown = false;
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            if (m.Msg == WM_QUERYENDSESSION)
            {                
                systemShutdown = true;
            }

            // If this is WM_QUERYENDSESSION, the closing event should be
            // raised in the base WndProc.
            base.WndProc(ref m);

        } //WndProc 

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            textBox1.Text = "Windows shutdown";
            File.AppendAllText("test.txt", "Windows shutdow");
        }
    }
}



Powered by Blogger.

Whatsapp Button works on Mobile Device only

Start typing and press Enter to search