Wednesday, 12 July 2017

A small C# application for Windows Lock, logOff, Restart and Shutdown.

Hi, Everyone!

                     Users can use different ways to shutdown their Computer Systems like Shutdown.
Today I will show some shortcut coding techniques to Windows Lock, Log off, Restart and Shutdown.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Bunifu.Framework;
using Bunifu.Framework.UI;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;

namespace Power
{
    public partial class Form1 : Form
    {
        [DllImport("user32")]
        public static extern void LockWorkStation();
        [DllImport("user32")]
        public static extern bool ExitWindowsEx(uint uFlags, uint dwReason);

        public Form1()
        {
            InitializeComponent();
        }

        private void btnLock_Click(object sender, EventArgs e)
        {
            LockWorkStation();
        }

        private void btnLogOff_Click(object sender, EventArgs e)
        {
            ExitWindowsEx(0, 0);            
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            Process.Start("shutdown", "/r /t 0");
        }

        private void btnShutdown_Click(object sender, EventArgs e)
        {
            Process.Start("shutdown", "/s /t 0");
        }




Thank you!

                                                                                                                          Santosh Kokatnur

No comments:

Post a Comment