473,396 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Starting Win32 Service

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
3 4849
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Xypher | last post by:
I wrote a pretty basic application in c++ which runs in a while (true) { //do something Sleep(xxx milliseconds); }
6
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
7
by: Ahmed Perlom | last post by:
Hi all, I am trying to start a windows application that has a GUI from a Windows service written in .NET 2.0. I have been searching on this for few days now with no avail. When using the...
0
by: Mark Henry | last post by:
I wrote a Desktop class for manipulating desktops and window stations. The class is being used by a service for starting applications on the interactive desktop (the service cannot run as Local...
1
Fatali
by: Fatali | last post by:
I found a bit of code here in the forums, that modified looked like it would do what I needed: start a Windows Service. The code said I would need to add : Imports System.ServiceProcess So I...
16
by: sunil | last post by:
Hi, I have a service written in c# that I need to run as a "Network Service". I am using a setup project to install the service. If I install the service in User's Personal Folder, I get the...
2
by: Gregor Mosheh | last post by:
I'm trying to write a Win32 service. The following is straight from Python Programming on Win32 and it doesn't work. Is that book out of date; is there a new way to do services? I searched Google...
0
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform...
5
by: eliasen | last post by:
Hi I have created a Windows Service using C# and .NET2.0. The service is quite simple - right now it doesn't do anything except throwing an exception in the OnStart method. It used to something...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.