Starting Win32 Service

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

    #1

    Starting Win32 Service

    Hi all,

    Using Tim Golden's wmi module you can get the service names

    import wmi
    c = wmi.WMI ()
    stopped_service s = c.Win32_Service (StartMode="Aut o", State="Stopped" )
    if stopped_service s:
    for s in stopped_service s:
    print s.Caption, "service is not running"
    else:
    print "No auto services stopped"




    but how do i start services that are stopped?

    Cheers

  • Gabriel Genellina

    #2
    Re: Starting Win32 Service

    At Wednesday 27/9/2006 01:39, placid wrote:
    >Using Tim Golden's wmi module you can get the service names
    >but how do i start services that are stopped?
    Surely there are fancier ways:
    >net start servicename


    Gabriel Genellina
    Softlab SRL





    _______________ _______________ _______________ _____
    Preguntá. Respondé. Descubrí.
    Todo lo que querías saber, y lo que ni imaginabas,
    está en Yahoo! Respuestas (Beta).
    ¡Probalo ya!


    Comment

    • placid

      #3
      Re: Starting Win32 Service


      Tim Golden wrote:
      [placid]
      | Using Tim Golden's wmi module you can get the service names
      |
      | import wmi
      | c = wmi.WMI ()
      | stopped_service s = c.Win32_Service (StartMode="Aut o", State="Stopped" )
      | if stopped_service s:
      | for s in stopped_service s:
      | print s.Caption, "service is not running"
      | else:
      | print "No auto services stopped"
      |
      | but how do i start services that are stopped?
      >
      <code>
      import wmi
      c = wmi.WMI ()
      for method in c.Win32_Service ._methods:
      print method
      >
      #
      #... includes StartService
      #
      >
      print c.Win32_Service .StartService
      >
      # <function StartService () =(ReturnValue)>
      >
      #
      # Therefore, to start all non-running auto services (!)
      #
      for service in c.Win32_Service (StartMode="Aut o", State="Stopped" ):
      print service.Caption
      service.StartSe rvice ()
      >
      </code>
      >
      TJG
      >
      Thanks for that.

      Now i was trying to use service.ChangeS tartMode but each time i pass in
      an argument i get the error;

      #TypeError: __call__() takes exactly 1 argument (2 given)

      but;
      >>print service.ChangeS tartMode
      <function ChangeStartMode (StartMode) =(ReturnValue)>

      ChangeStartMode needs an argument!

      What im i doing wrong here?

      Cheers

      Comment

      • placid

        #4
        Re: Starting Win32 Service


        placid wrote:
        Tim Golden wrote:
        [placid]
        | Using Tim Golden's wmi module you can get the service names
        |
        | import wmi
        | c = wmi.WMI ()
        | stopped_service s = c.Win32_Service (StartMode="Aut o", State="Stopped" )
        | if stopped_service s:
        | for s in stopped_service s:
        | print s.Caption, "service is not running"
        | else:
        | print "No auto services stopped"
        |
        | but how do i start services that are stopped?

        <code>
        import wmi
        c = wmi.WMI ()
        for method in c.Win32_Service ._methods:
        print method

        #
        #... includes StartService
        #

        print c.Win32_Service .StartService

        # <function StartService () =(ReturnValue)>

        #
        # Therefore, to start all non-running auto services (!)
        #
        for service in c.Win32_Service (StartMode="Aut o", State="Stopped" ):
        print service.Caption
        service.StartSe rvice ()

        </code>

        TJG
        >
        Thanks for that.
        >
        Now i was trying to use service.ChangeS tartMode but each time i pass in
        an argument i get the error;
        >
        #TypeError: __call__() takes exactly 1 argument (2 given)
        >
        but;
        >
        >print service.ChangeS tartMode
        <function ChangeStartMode (StartMode) =(ReturnValue)>
        >
        ChangeStartMode needs an argument!
        >
        What im i doing wrong here?
        And to answer my own question, the way to pass in arguments is via the
        key=value way so;

        service.ChangeS tartMode(StartM ode = "Automatic" )

        Cheers

        P.S: Dont you just love trial and error/brute force?

        Comment

        Working...