65.9K
CodeProject is changing. Read more.
Home

How to Shut Down and Restart your computer with a simple program in C#

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.67/5 (6 votes)

Jul 16, 2016

CPOL
viewsIcon

9897

You can used it for shutdown And restart Your computer .

Introduction

Simple idea , This tip to how shut down and restart your PC . 

Background

This tip is based on a System32 Files whose address is Windows\System32\Shutdown.exe

Using the code

So for doing what we want, we must follow the steps given below ; 

1- Create New Project With C#

2- make your desing of Program  , You Need Add two buttons on form .

3- Use This code  : 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;

namespace Shutdown_PC
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

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