Restart operations

You can use below script to restart machine,

import subprocess;
sysdown=subprocess.Popen(('shutdown /r '),shell=True,stdout=subprocess.PIPE);
for line in iter(sysdown.stdout.readline,''):
    print line.rstrip();

Note: please refer attach text file for script text without indentation error.

No STDOUT text for this script. You need to check success or failed status .

Options:

use ‘shutdown /s’ to shutdown
use ‘shutdown /l’ to logoff

restart.txt (170 Bytes)

@mkannan,

Thanks for the scripts.
For this one particularly, I was testing it out and I can’t seem to get the ‘shudown /l’ option to work.
As you instructed, simply replace the /r in the original script to change to /s for shutdown and /l for logoff.
I managed to get /s for shutdown to work but not /l.
The error that it gives you is:

Incorrect function.(1)

I’m not too sure what is wrong but I thought I should let you know.

Thanks.

Hi @Ming

Please try below script to log off

import os
os.popen('shutdown -l')