using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics; // add this namespace
namespace DemoConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string filename = "", arguments = "", value = "";
Console.WriteLine("\nShut Down\nRestart\nLogoff\nLock\nHibernation\nSleep\n\nEnter your Choice:");
string oparation = Console.ReadLine();
oparation = oparation.ToUpper(); // convert input into uppercase
value = oparation.Trim(); // for remove whitespace from string
switch (value)
{
case "SHUTDOWN":
filename = "shutdown.exe";
arguments = "-s";
break;
case "RESTART":
filename = "shutdown.exe";
arguments = "-r";
break;
case "LOGOFF":
filename = "shutdown.exe";
arguments = "-l";
break;
case "LOCK":
filename = "Rundll32.exe";
arguments = "User32.dll, LockWorkStation";
break;
case "HIBERNATION":
filename = @ "%windir%\system32\rundll32.exe";
arguments = "PowrProf.dll, SetSuspendState";
break;
case "SLEEP":
filename = "Rundll32.exe";
arguments = "powrprof.dll, SetSuspendState 0,1,0";
break;
}
ProcessStartInfo startinfo = new ProcessStartInfo(filename, arguments);
Process.Start(startinfo);
}
}
}Output:

