Click here to Skip to main content
15,890,982 members
Articles / Programming Languages / C#
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
2.67/5 (6 votes)
16 Jul 2016CPOL 9.4K   3   5
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  : 

C++
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");
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student
Iraq Iraq
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionYou wrote a program to run a program? Pin
John Brett17-Jul-16 20:28
John Brett17-Jul-16 20:28 
AnswerRe: You wrote a program to run a program? Pin
PeejayAdams18-Jul-16 0:45
PeejayAdams18-Jul-16 0:45 
AnswerRe: You wrote a program to run a program? Pin
Marco Bertschi18-Jul-16 4:26
protectorMarco Bertschi18-Jul-16 4:26 
GeneralMy vote of 4 Pin
dcmuggins17-Jul-16 6:16
professionaldcmuggins17-Jul-16 6:16 
GeneralMy vote of 5 Pin
Аslam Iqbal16-Jul-16 22:18
professionalАslam Iqbal16-Jul-16 22:18 
nice

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.