Problem remotely shutting down a windows computer with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • EW

    #1

    Problem remotely shutting down a windows computer with python

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



    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

  • Daniel Bickett

    #2
    Re: Problem remotely shutting down a windows computer with python

    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 <ewanon@gmail.c om> wrote:[color=blue]
    > I have a problem when using the python script found here:
    >
    > http://aspn.activestate.com/ASPN/Coo.../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
    >[/color]

    Comment

    • EW

      #3
      Re: Problem remotely shutting down a windows computer with python

      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.

      Comment

      • Kartic

        #4
        Re: Problem remotely shutting down a windows computer with python

        Hi,

        According to the online docs for InitiateSystemS hutdown() at



        bRebootAfterShu tdown : 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/de...emshutdown.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

        Comment

        • Duncan Booth

          #5
          Re: Problem remotely shutting down a windows computer with python

          Kartic wrote:
          [color=blue]
          > 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).
          >[/color]

          Or invoke 'shutdown -s -m \\machinename' on the local machine to shutdown a
          remote machine.

          Comment

          • Tim G

            #6
            Re: Problem remotely shutting down a windows computer with python

            > I have a problem when using the python script found here:[color=blue]
            >
            > http://aspn.activestate.com/ASPN/Coo.../Recipe/360649
            >
            > It is a script to remotely shutdown a windows computer. When I use[/color]
            it,[color=blue]
            > 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[/color]
            push[color=blue]
            > the power button to actually power off. Anyone know why this happens
            > with this script? Thanks for any help.
            >
            > Eric[/color]

            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="othe r_machine", privileges=["RemoteShutdown "])
            os = c.Win32_Operati ngSystem (Primary=1)[0]
            os.Win32Shutdow n (Flags=12)
            </code>

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

            TJG

            Comment

            • EW

              #7
              Re: Problem remotely shutting down a windows computer with python

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

              Eric

              Comment

              Working...