How to Log off from Windows programmatically using C# ?
Below is a simple program that lets you to Log off Windows programmatically using C# .
The P/Invoke’s ExitWindowsEx method is used to Log off from Windows using C# .
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { [DllImport("user32.dll")] static extern bool ExitWindowsEx(uint uFlags, uint dwReason); static void Main(string[] args) { ExitWindowsEx(0, 0); } } }