Hello. I have come across many scripts for rebooting remote computers using python, but what about the computer the script is running on? If possible, I would also like my script to run in the background so the little cmd box is not visible. Thanks in advance for your help.

I think you can have it pass the command to the computer via the os module. Like for Debian-based GNU/Linux distros you could write:

import os
os.system("halt")

The only problem I can think of is that this would require super-user privileges to execute the shut down.

With Windows, if you have the win32api module, you can try this:

import win32api
win32api.InitiateSystemShutdown()

I haven't tried that before though, so you may want to look deeper into that. Hope I helped a bit!

Thanks for your help... it seems that command would work.. except it give me a type error.

import win32api
win32api.InitiateSystemShutdown()
TypeError: InitiateSystemShutdown() takes exactly 5 arguments (0 given)

I will look for the documentation in the meantime.

This post on stackoverflow seems to have the skeleton code for going about and making it a service.

And there's something about using srvany.exe here.

I've never actually done this myself so I can't offer much more insight...

Thanks. I didn't end up doing that exactly, but I greatly appreciate your help nonetheless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.