473,386 Members | 1,832 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,386 software developers and data experts.

Check a windows service

Hi,

I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?

Thanks

Jan 16 '07 #1
9 14862
awel wrote:
I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?
This is one way:

http://tgolden.sc.sabren.com/python/...matic_services

You'd have to change that example slightly, but I
hope the principal is clear enough. If not, ask again.

TJG

Jan 16 '07 #2
On 16 Jan 2007 09:09:34 -0800, Tim Golden <tj******@gmail.comwrote:
awel wrote:
I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?

This is one way:

http://tgolden.sc.sabren.com/python/...matic_services

You'd have to change that example slightly, but I
hope the principal is clear enough. If not, ask again.

TJG
Here's some code cut & pasted from the demos included in the win32 module:

import win32service
import win32con
def EnumServices():
resume = 0
accessSCM = win32con.GENERIC_READ
accessSrv = win32service.SC_MANAGER_ALL_ACCESS

#Open Service Control Manager
hscm = win32service.OpenSCManager(None, None, accessSCM)

#Enumerate Service Control Manager DB

typeFilter = win32service.SERVICE_WIN32
stateFilter = win32service.SERVICE_STATE_ALL

statuses = win32service.EnumServicesStatus(hscm, typeFilter, stateFilter)
for (short_name, desc, status) in statuses:
print short_name, desc, status
Jan 16 '07 #3
"awel" <al************@gmail.comescribió en el mensaje
news:11*********************@l53g2000cwa.googlegro ups.com...
I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?
Yes, using the wmi module, but you'll have to search the Microsoft
documentation on how to enumerate services and their properties:
http://msdn2.microsoft.com/en-us/library/aa384642.aspx
The code might look like this, but the names may be wrong:

import wmi
import pythoncom
pythoncom.CoInitialize()
w = wmi.WMI()
for s in w.Win32_Services():
print s

--
Gabriel Genellina
Jan 16 '07 #4
Sorry, but could you give me an example with a real service 'cause I've
tried this script but nothings happened, no error, nothings ; even if I
launch it in cmd prompt.

Thanks

Tim Golden a écrit :
awel wrote:
I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?

This is one way:

http://tgolden.sc.sabren.com/python/...matic_services

You'd have to change that example slightly, but I
hope the principal is clear enough. If not, ask again.

TJG
Jan 16 '07 #5
Sorry, but could you give me an example with a real service 'cause I've
tried this script but nothings happened, no error, nothings ; even if I
launch it in cmd prompt.

Thanks

Tim Golden a écrit :
awel wrote:
I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?

This is one way:

http://tgolden.sc.sabren.com/python/...matic_services

You'd have to change that example slightly, but I
hope the principal is clear enough. If not, ask again.

TJG
Jan 16 '07 #6
Sorry, but could you give me an example with a real service 'cause I've
tried this script but nothings happened, no error, nothings ; even if I
launch it in cmd prompt.

Thanks
Chris Mellon a écrit :
On 16 Jan 2007 09:09:34 -0800, Tim Golden <tj******@gmail.comwrote:
awel wrote:
I'm new in python and I would like to know if it's possible to check if
a specific windows service is present and if it's possible how can I
do?
This is one way:

http://tgolden.sc.sabren.com/python/...matic_services

You'd have to change that example slightly, but I
hope the principal is clear enough. If not, ask again.

TJG

Here's some code cut & pasted from the demos included in the win32 module:

import win32service
import win32con
def EnumServices():
resume = 0
accessSCM = win32con.GENERIC_READ
accessSrv = win32service.SC_MANAGER_ALL_ACCESS

#Open Service Control Manager
hscm = win32service.OpenSCManager(None, None, accessSCM)

#Enumerate Service Control Manager DB

typeFilter = win32service.SERVICE_WIN32
stateFilter = win32service.SERVICE_STATE_ALL

statuses = win32service.EnumServicesStatus(hscm, typeFilter, stateFilter)
for (short_name, desc, status) in statuses:
print short_name, desc, status
Jan 16 '07 #7
At Tuesday 16/1/2007 19:19, awel wrote:
>Sorry, but could you give me an example with a real service 'cause I've
tried this script but nothings happened, no error, nothings ; even if I
launch it in cmd prompt.
You have to call the EnumServices function if you want some useful output.
Copy&paste the code in a new file, add these 2 lines at the end, and
save the file with a .py extension:

if __name__=='__main__':
EnumServices()

Then execute it with: python your_file_name.py
See
http://diveintopython.org/getting_to...g_modules.html
to understand what's that; and read the whole book, it's a good
tutorial if you already know another language.
--
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

Jan 17 '07 #8
awel wrote:
Sorry, but could you give me an example with a real service 'cause I've
tried this script but nothings happened, no error, nothings ; even if I
launch it in cmd prompt.
Well, as that example said, it was designed to show
automatic services which are not running. If you don't
have any then nothing will show. I assumed you could
use this as a starting point.

To list all services try this:

<code>
import wmi

c = wmi.WMI ()
for service in c.Win32_Service ():
print service.Caption

</code>

To show a specific service:

<code>
import wmi

c = wmi.WMI ()
for service in c.Win32_Service (Caption="Task Scheduler"):
print service

</code>

TJG

Jan 17 '07 #9
Thanks for all 'cause you've really helped me

Just one thing in the last line for the specific service, you' ve
writted :
print service
but I think it is :
print service.Caption

Tim Golden a écrit :
awel wrote:
Sorry, but could you give me an example with a real service 'cause I've
tried this script but nothings happened, no error, nothings ; even if I
launch it in cmd prompt.

Well, as that example said, it was designed to show
automatic services which are not running. If you don't
have any then nothing will show. I assumed you could
use this as a starting point.

To list all services try this:

<code>
import wmi

c = wmi.WMI ()
for service in c.Win32_Service ():
print service.Caption

</code>

To show a specific service:

<code>
import wmi

c = wmi.WMI ()
for service in c.Win32_Service (Caption="Task Scheduler"):
print service

</code>

TJG
Jan 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eric Chong | last post by:
I created a Windows Service in C# that requires to get passed command arguments like a Console App. I noticed that there is an option "Start parameters" text box in the property of a Windows...
0
by: Marina | last post by:
Hi, I need to have a windows service that can access various DLL's dynamically. These dll's are stored in a particular directory, but of course this can vary by application. The problem is...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
3
by: Chuck Bowling | last post by:
Ok, I'm not sure this is a C# question but here goes anyhow... I used this walkthru to create a windows service: ...
5
by: Andrew | last post by:
Hey all, Requesting help from the VB.Net gurus in here. I was given a task to write a Windows Service (VB.Net) that would run an external program, and if that program closed for any reason...
4
by: Blaxer | last post by:
I have read approximately 30 articles now on various methods to make your vb.net application automatically update itself and I can't see how they apply to a vb.net windows services projects. The...
1
by: PankajLohani | last post by:
hello, This is very challenging problem for me. basically my windows service monitor the application when my application hang due any reason then my service kill that process and application .Then...
3
by: John Wright | last post by:
I need to know how to check the state of a windows service. I need to determine if the windows service "Smart Card" is running. If it is not running, I need to start the service. Also it would...
6
by: DM | last post by:
Hi All, I have written a server program which distributes real-time data to our customers and is also used by our customers to redistribute this data over their internal networks. The program is...
6
by: Christiano Donke | last post by:
Hey there... Plz... I'm writing a Windows Service that will check every x minutes if another program is running. If it cannot find the application running, it launches it... I had already...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.