.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Network >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Shutdown, restart, logoff, hibernate in c#.net

Posted By:laptop charles       Posted Date: August 15, 2010    Points: 15    Category: Network    URL: http://www.dotnetspark.com  

Shutdown, restart, logoff, hibernate your system/computer using C# programmatically using windows API

It contain four button .
One is shutdown,log off,hibernate,restart.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace Shutdownhiberstandrestart
    public partial class Form1 : Form
        public Form1()
        public static extern int ExitWindowsEx(int operationFlag, int operationReason);

        private void btnShutDown_Click(object sender, EventArgs e)

            ExitWindowsEx(1, 0);

        private void btnHibernate_Click(object sender, EventArgs e)
            Application.SetSuspendState(PowerState.Hibernate, true, true);

        private void btnRestart_Click(object sender, EventArgs e)
            ExitWindowsEx(2, 0);

        private void btnStandby_Click(object sender, EventArgs e)
            ExitWindowsEx(0, 0);


Further Readings:

Author: Saad Bin Saulat         Company URL: http://www.dotnetspark.com
Posted Date: February 16, 2011

To get source code in c#.net for shutdown,logoff and restart command, visit this cool link:

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend