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
    {
        
        static extern bool ExitWindowsEx(uint uFlags, uint dwReason);

        static void Main(string[] args)
        {
            ExitWindowsEx(0, 0);
        }
    }
}
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
Pin It

One thought on “How to Log off Windows programmatically using C# ?

  1. Pingback: Interesting .NET Links - October 11 , 2012 | TechBlog

Leave a Reply

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