HomeCSharpHow to Log off Windows programmatically using C# ?

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

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...