Python OS – Restart your machine in Python

In this post we will be creating a script in Python that will restart your machine, the following is only applicable for Windows machines. To do this we will be using Pythons OS module which will enable us to functionality on the systems operating system.

The script will ask the user to confirm whether or not they are wanting to restart the machine and to do this we will be taking input.

The source code for this project can be found below.

import os

while True:
    In = input("Do you want to restart your machine now?(Y/N) ")
    if In == "Y":
        os.system("shutdown /r /t 1")
    if In == "N":

Leave a Reply