[C# Code] Shutdown computer using C#

Shutdown computer using C# | C# Code to Shutdown Computer

In this article, learn how to perform shutdown through simple C# code. By writing few lines of code you can create an executable that shutdown your computer with a single click.


Shutdown Computer using C# code:

using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            ShutDown();
        }

        /// 
        /// Function to shutdown the computer.
        /// 
        public static void ShutDown()
        {
            Process.Start("shutdown", "/s /t 0");
        }

        /// 
        /// Function to perform silent computer shutdown.
        /// 
        public static void ShutDown2()
        {
            var process = new ProcessStartInfo("shutdown", "/s /t 0");
            process.CreateNoWindow = true;
            process.UseShellExecute = false;
            Process.Start(process);
        }
    }
}

using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
    public class Program
    {
        public static void Main()
        {
            ShutDown();
        }

        /// 
        /// Function to perform silent computer shutdown.
        /// 
        public static void ShutDown()
        {
            var process = new ProcessStartInfo("shutdown", "/s /t 0");
            process.CreateNoWindow = true;
            process.UseShellExecute = false;
            Process.Start(process);
        }
    }
}


– Article ends here –

If you have any questions, please feel free to share your questions or comments on the comment box below.

Share this:
We will be happy to hear your thoughts

      Leave a reply

      www.troubleshootyourself.com
      Logo