By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,929 Members | 634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,929 IT Pros & Developers. It's quick & easy.

Starting Win32 Service

P: n/a
Hi all,

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

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

http://tgolden.sc.sabren.com/python/...matic_services
but how do i start services that are stopped?

Cheers

Sep 27 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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!
http://www.yahoo.com.ar/respuestas

Sep 27 '06 #2

P: n/a

Tim Golden wrote:
[placid]
| Using Tim Golden's wmi module you can get the service names
|
| import wmi
| c = wmi.WMI ()
| stopped_services = c.Win32_Service (StartMode="Auto", State="Stopped")
| if stopped_services:
| for s in stopped_services:
| 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="Auto", State="Stopped"):
print service.Caption
service.StartService ()

</code>

TJG
Thanks for that.

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

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

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

ChangeStartMode needs an argument!

What im i doing wrong here?

Cheers

Sep 28 '06 #3

P: n/a

placid wrote:
Tim Golden wrote:
[placid]
| Using Tim Golden's wmi module you can get the service names
|
| import wmi
| c = wmi.WMI ()
| stopped_services = c.Win32_Service (StartMode="Auto", State="Stopped")
| if stopped_services:
| for s in stopped_services:
| 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="Auto", State="Stopped"):
print service.Caption
service.StartService ()

</code>

TJG

Thanks for that.

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

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

but;
>print service.ChangeStartMode
<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.ChangeStartMode(StartMode = "Automatic")

Cheers

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

Sep 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.