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 9 14870
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
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
"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
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
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
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |