Search This Blog

Showing posts with label log out. Show all posts
Showing posts with label log out. Show all posts

How to Logoff or Sign Out Windows Using Java Code

You can sign out the current user account from windows using java code. Sign out, log out or logoff button can be created using simple lines of code. To logout from Windows operating system using java code, use the following code:


try {
        Runtime.getRuntime().exec("shutdown /l");
    } catch (IOException ex) {}

As the above code shows, we are simply executing a cmd command shutdown /l. It is actually running shutdown.exe with parameter /l to force logoff. If you add above code in the actionPerformed() function of a button, the button becomes a logoff button. The following video will show an example in which a simple button is made into a logout button.