Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically restart windows to make system logs think user logged out

I'm hoping to make a quick script to log-out/restart windows at a set time. For example, start a script to "Restart windows in ten minutes". For this implementation I don't need it to run in the background or pop=up on its own. I just want to set the script and walk away knowing that the computer will log-out/restart at a set time.

Why would I want to do this? On a corporate network, sometimes system logs will be reviewed and if one is found to be leaving X minutes too early, then complications arise. Kinda annoying.

Did I already Google it? Yep. I found this. But it wasn't too helpful. It requires a framework I couldn't find, and likely couldn't install since we don't have admin privs on these machines.

I'd like to use Python for it, and I'd really like for it to look like the user did it, not a script. Perhaps screen scraping would be the only way, and if so just point me to a quick guide or IDE and I'll post the source code for everyone.

EDIT: I also ran into this

like image 665
Jon W Avatar asked Dec 17 '22 08:12

Jon W


2 Answers

The shutdown command in batch will shutdown the computer

-s to turn it off, -f to force it, -t xx to have it shutdown in x seconds,

use the subprocess module in python to call it.

Since you want it to shutdown at a specific time, to automate the job completely you'd need to use something like autosys. Set the script up to call shutdown with a value for T equal to time you want to shut down - current time in seconds. Run it before you leave for the day, or have it set to run on start up and just ignore that stupid window it brings up.

like image 85
gone Avatar answered Dec 26 '22 06:12

gone


PsShutdown is probably what you are looking for.

like image 43
Sanjaya R Avatar answered Dec 26 '22 07:12

Sanjaya R