[Tutor] Shut down PC

Michael Janssen Janssen at rz.uni-frankfurt.de
Mon Aug 2 19:40:17 CEST 2004


On Mon, 2 Aug 2004, David Holland wrote:

> Hi I have both Windows and Linux on my PC.
> Basically I want the operating system to terminate if
> people using the PC do not know a password and do not
> answers questions  within a time limit


on Linux you can stop the computer with "/sbin/init 0" (besides various
other commands). This will switch into runlevel 0, ie halt. Permissions
might be set accordingly. os.system is the Python function to call
external commands.

Windows can be stopped with a much more complicated command using
rundll32. rundll32 is used to run methods from dll-files (libraries) on
their own. Perhaps google knows more about the proper library to use and
the name of the shutdow method.

Perhaps win32all has something to offer:
http://starship.python.net/crew/mhammond/win32/


> or if they try to avoid doing these questions by crashing the program.

try: main()
except:
    os.system("/sbin/init 0")

should catch some tricks but suspending the programm isn't catched and
probably more things. Besides it's a funny way to make writing and
debugging a Python script more risky ;-)


Michael


More information about the Tutor mailing list