As we know, Python is a popular scripting language because of its versatile features. In this article, we will write a Python script to logout a computer. Let’s start with how to logout the system with Python. To logout your computer/PC/laptop only by using a Python script, you have to use the os.system() function with the code “shutdown -l” . The shutdown -l command is the windows shell command for logging off.
Let’s start with how to log out the system with Python.
Note: For this to work, you have to import os library in the ide. If you don’t have it, then ‘
pip install os‘ through the Command Prompt.Causion: Please ensure that you save and close all the program before running this code on the IDLE, as the below program will immediately log out your computer.
Below is the Python implementation –
import os logout = input("Do you wish to log out your computer ? (yes / no): ") if logout == 'no': exit() else: os.system("shutdown -l") |
Output:

Here is the Python Program which will ask the user to log out the computer providing the option of Yes or No. Also, when you type yes & then press the ENTER key, the system will be log out instantly.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- GUI to Shutdown, Restart and Logout from the PC using Python
- Python Script to Shutdown Computer
- Python Script to Restart Computer
- Python | Add Logging to a Python Script
- Competitive Coding Setup for C++ and Python in VS Code using Python Script
- Python script to open a Google Map location on clipboard
- Run Python script from Node.js using child process spawn() method
- Autorun a Python script on windows startup
- Python | Accepting Script Input
- Running Python script on GPU.
- Run python script from anywhere in linux
- Get directory of current Python script
- How to Run a Python Script
- Schedule a Python Script on PythonAnywhere
- Convert Python Script to .exe File
- Add a User in Linux using Python Script
- Deleting a User in Linux using Python Script
- Get Your System Information - Using Python Script
- Python script to change MAC address of Linux machine
- Run Python Script using PythonShell from Node.js
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

