How to make a python script which can logoff, shutdown, and restart a computer?

前端 未结 3 1881
你的背包
你的背包 2020-12-16 06:02

Background

I am currently in the process of teaching myself python, and I thought that it would be a very cool project to have a sort of \"control c

3条回答
  •  情书的邮戳
    2020-12-16 06:28

    To restart:

    shutdown /r
    

    To log off:

    shutdown /l
    

    The final code block (as requested):

    Log off:

    def shutdown(self):
        import subprocess
        subprocess.call(["shutdown", "-f", "-s", "-t", "60"])
    

    Restart:

    def shutdown(self):
        import subprocess
        subprocess.call(["shutdown", "-f", "-r", "-t", "60"])
    

提交回复
热议问题