#1
  1. Caress me down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Pennsylvania
    Posts
    289
    Rep Power
    511

    computer restart


    how can i write a program that will restart my computer after a certain amout of time? is there an actual command that will restart my computer programmed into python?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    84
    Rep Power
    11
    Originally Posted by lw22
    how can i write a program that will restart my computer after a certain amout of time? is there an actual command that will restart my computer programmed into python?
    what OS are you running? if you're on unix, you could just run a command through os.system("shutdown -r now"). if you're on windows, you could do something similar with os.system("C:/WINDOWS/RUNDLL32.EXE user,exitwindows") [not sure if the windows one works, never tried it]

    to achieve a timed shutdown on windows, you could try:

    Code:
    import os
    import time
    ...
    seconds = int(raw_input("Seconds until shutdown: "))
    if (seconds >= 0): # let the user enter -1 if they want to cancel
        time.sleep(seconds)
        os.system("C:/windows/rundll32.exe user,exitwindows")
    this is off the top of my head and untested, so yeah... hope it works

    oh and as far as I know, there is no actual 'shutdown' command 'built in' to python.

    [edit]
    I just googled it a bit, and found that the command for shutting down windows varies from version to version. the one above is for 9x boxes and maybe 2k as well. on xp you can use "shutdown -t [number of seconds]", so you don't need to worry about using sleep. also you can use the '-r' option to restart instead of shutdown.
    [/edit]
    Last edited by rebbit; April 6th, 2005 at 06:31 AM. Reason: found some more info

IMN logo majestic logo threadwatch logo seochat tools logo