Problem remotely shutting down a windows computer with python

Discussion in 'Python' started by EW, Jan 3, 2005.

  1. EW

    EW Guest

    I have a problem when using the python script found here:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649

    It is a script to remotely shutdown a windows computer. When I use it,
    the computer shuts down, but doesn't power off like with a regular
    shutdown. It stays on the "Safe to power off" screen and I have to push
    the power button to actually power off. Anyone know why this happens
    with this script? Thanks for any help.

    Eric
     
    EW, Jan 3, 2005
    #1
    1. Advertising

  2. While I have no solution for the recipe you cited, it seems like alot
    of trouble could be avoided by simply importing the os module and
    running the following command using os.system:

    shutdown -s

    Daniel Bickett


    On 2 Jan 2005 20:13:35 -0800, EW <> wrote:
    > I have a problem when using the python script found here:
    >
    > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649
    >
    > It is a script to remotely shutdown a windows computer. When I use it,
    > the computer shuts down, but doesn't power off like with a regular
    > shutdown. It stays on the "Safe to power off" screen and I have to push
    > the power button to actually power off. Anyone know why this happens
    > with this script? Thanks for any help.
    >
    > Eric
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Daniel Bickett, Jan 3, 2005
    #2
    1. Advertising

  3. EW

    EW Guest

    I believe that would shutdown the computer you were physically at, but
    it wouldn't shutdown the computer down the hall over the LAN like this
    script was meant to do.
     
    EW, Jan 3, 2005
    #3
  4. EW

    Kartic Guest

    Hi,

    According to the online docs for InitiateSystemShutdown() at
    http://aspn.activestate.com/ASPN/do...32/win32api__InitiateSystemShutdown_meth.html


    bRebootAfterShutdown : int

    Specifies whether the computer is to restart immediately after
    shutting down. If this parameter is TRUE, the computer is to restart.
    If this parameter is FALSE, the system flushes all caches to disk,
    clears the screen, and displays a message indicating that it is safe to
    power down.


    Same at Microsoft for the Win32 API Call -
    http://msdn.microsoft.com/library/d...en-us/sysinfo/base/initiatesystemshutdown.asp

    Looks like this is the documented outcome. You could alternatively try
    setting a little XML-RPC app to invoke 'shutdown -s' on the remote PC
    from your PC (e.g. using Twisted Python).

    Thanks,
    --Kartic
     
    Kartic, Jan 3, 2005
    #4
  5. EW

    Duncan Booth Guest

    Kartic wrote:

    > Looks like this is the documented outcome. You could alternatively try
    > setting a little XML-RPC app to invoke 'shutdown -s' on the remote PC
    > from your PC (e.g. using Twisted Python).
    >


    Or invoke 'shutdown -s -m \\machinename' on the local machine to shutdown a
    remote machine.
     
    Duncan Booth, Jan 3, 2005
    #5
  6. EW

    Tim G Guest

    > I have a problem when using the python script found here:
    >
    > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649
    >
    > It is a script to remotely shutdown a windows computer. When I use

    it,
    > the computer shuts down, but doesn't power off like with a regular
    > shutdown. It stays on the "Safe to power off" screen and I have to

    push
    > the power button to actually power off. Anyone know why this happens
    > with this script? Thanks for any help.
    >
    > Eric


    I see that others have answered the question
    pretty completely, but just to add the obligatory
    WMI solution:
    [ assumes you're using the wmi module from
    http://tgolden.sc.sabren.com/python/wmi.html ]

    <code>

    import wmi
    c = wmi.WMI (computer="other_machine", privileges=["RemoteShutdown"])
    os = c.Win32_OperatingSystem (Primary=1)[0]
    os.Win32Shutdown (Flags=12)
    </code>

    The Flags=12 bit should shut down all the way.

    TJG
     
    Tim G, Jan 4, 2005
    #6
  7. EW

    EW Guest

    This does exactly what I needed! Thanks! Not sure what Windows
    Management Instrumentation is, but I'll look into it now.

    Eric
     
    EW, Jan 7, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Qm9zc29tYQ==?=

    Windows 98 SE freezes when shutting down.

    =?Utf-8?B?Qm9zc29tYQ==?=, Jun 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    596
    Eddie
    Jun 27, 2005
  2. Jesper
    Replies:
    10
    Views:
    4,478
    D. Rush
    Sep 29, 2004
  3. Rolf Magnus

    Shutting down Windows 2K +

    Rolf Magnus, Jul 23, 2003, in forum: C++
    Replies:
    9
    Views:
    388
    Scott Condit
    Jul 24, 2003
  4. Replies:
    3
    Views:
    1,065
    bruno at modulix
    May 16, 2006
  5. Jack
    Replies:
    2
    Views:
    1,616
Loading...

Share This Page