Shutdown computer using C# code

In this article, learn how to perform shutdown computer using C# code.


Shutdown computer using C#:

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:   How to Calculate relative time in C#
Share this:

Tags:

We will be happy to hear your thoughts

Leave a reply

Troubleshootyourself
Logo