How to shutdown a computer using Python

Ben L picture Ben L · Dec 2, 2015 · Viewed 59.6k times · Source

I've written a Python script which should eventually shutdown the computer.

This line is a part of it :

os.system("shutdown /p")

It makes some sort of a shutdown but remains on the turn-on Windows control pannel (where the user can switch the computer users).

Is there a way to fully shutdown the computer?

I've tried other os.system("shutdown ___") methods with no success.

Is there another method which might help?

Answer

shiva1791 picture shiva1791 · Dec 2, 2015
import os
os.system('shutdown -s')

This will work for you.