Shutdown computer using C#

In this article, learn how to perform shutdown through simple C# code.


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.

Recommended:   Creating EventLog in C# | Windows EventViewer
Share this:
We will be happy to hear your thoughts

Leave a reply

Troubleshootyourself
Logo