How to Log off Windows programmatically using C# ?

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);
        }
    }
}

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...