473,895 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Description Field in WinXP Services

rbt
How does one associate a "Descriptio n" with a Windows service written in
Python? I've just started experimenting with Python services. Here's my
code... copied straight from Mr. Hammond's "Python Programming on Win32":

import win32serviceuti l
import win32service
import win32event

class test_py_service (win32serviceut il.ServiceFrame work):
_svc_name_ = "test_py_servic e"
## Tried the following to no avail.
_svc_descriptio n_ = "Test written by Brad"
_svc_display_na me_ = "Test Python Service"

def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)

def SvcDoRun(self):
win32event.Wait ForSingleObject (self.hWaitStop ,
win32event.INFI NITE)
if __name__ == '__main__':
win32serviceuti l.HandleCommand Line(test_py_se rvice)

Jul 18 '05 #1
4 2252
ChangeServiceCo nfig2 is the api functions that sets the description,
but it's not in the win32service module (yet).

Roger

"rbt" <rb*@athop1.ath .vt.edu> wrote in message
news:ct******** **@solaris.cc.v t.edu...
How does one associate a "Descriptio n" with a Windows service written in
Python? I've just started experimenting with Python services. Here's my
code... copied straight from Mr. Hammond's "Python Programming on Win32":

import win32serviceuti l
import win32service
import win32event

class test_py_service (win32serviceut il.ServiceFrame work):
_svc_name_ = "test_py_servic e"
## Tried the following to no avail.
_svc_descriptio n_ = "Test written by Brad"
_svc_display_na me_ = "Test Python Service"

def __init__(self, args):
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
self.hWaitStop = win32event.Crea teEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServ iceStatus(win32 service.SERVICE _STOP_PENDING)
win32event.SetE vent(self.hWait Stop)

def SvcDoRun(self):
win32event.Wait ForSingleObject (self.hWaitStop ,
win32event.INFI NITE)
if __name__ == '__main__':
win32serviceuti l.HandleCommand Line(test_py_se rvice)



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jul 18 '05 #2
rbt
Roger Upole wrote:
ChangeServiceCo nfig2 is the api functions that sets the description,
but it's not in the win32service module (yet).

Roger


OK, I can use _winreg to add the 'Description' field under the
appropriate registry key.
Jul 18 '05 #3
rbt
rbt wrote:
Roger Upole wrote:
ChangeServiceCo nfig2 is the api functions that sets the description,
but it's not in the win32service module (yet).

Roger

OK, I can use _winreg to add the 'Description' field under the
appropriate registry key.


Here's an example of it... kludgey but it works ;)

from _winreg import *
import time

def Svc_Description ():
try:
key_location = r"SYSTEM\Curren tControlSet\Ser vices\test_py_s ervice"
svc_key = OpenKey(HKEY_LO CAL_MACHINE, key_location, 0, KEY_ALL_ACCESS)
SetValueEx(svc_ key,'Descriptio n',0,REG_SZ,u"B rad's Test Python Service")
CloseKey(svc_ke y)
except Exception, e:
print e

Svc_Description ()
time.sleep(10)
Jul 18 '05 #4
Roger,

I wrote an extension to Mark Hammond's win32serviceuti l.ServiceFramew ork class
(that I submitted to him also) that extends the class to provide you with this
functionality (along with the ability to support py2exe frozen services better).

Here it is:

import _winreg
import os
import win32evtlogutil

class NTserviceBase:
'''
Written by: Larry A. Bates - Syscon, Inc. March 2004

This is a base class for creating new NTservices with Python.
It should be included when you are defining your class as follows:

class newNTservice(wi n32serviceutil. ServiceFramewor k, NTserviceBase):
#
# Required attributes for a service
#
_svc_name_="new NTservice"
_svc_display_na me_="newNTservi ce"
_svc_descriptio n_='newNTservic e is a service that can be installed ' \
'and 'run on any Windows NT, 2000, XP, 2003 ' \

'computer. It can be controlled by services applet' \
'in the Control Panel and will run unattended ' \
'after being started.'

def __init__(self, args):
NTserviceBase._ _init__(self)
win32serviceuti l.ServiceFramew ork.__init__(se lf, args)
#
# Create an event which we will use to wait on.
# The "service stop" request will set this event.
#
self.hWaitStop= win32event.Crea teEvent(None, 0, 0, None)
return

Note: the __init__ method of the created class should call the __init__
method of NTserviceBase AND win32serviceuti l.ServiceFramew ork to get
everything initialized properly
'''
def __init__(self):
#-------------------------------------------------------------------
# Call function to set self.PythonServ ice (0=binary, 1=Python)
#-------------------------------------------------------------------
self.getSERVICE type()
self.installpat h=self.getSERVI CEpath()
#-------------------------------------------------------------------
# Call function to set Service's long description string. Can't
# seem to find a way to do this that works for both PythonServices
# and binary (py2exe) services. So I will set the description
# every time the service is started.
#-------------------------------------------------------------------
self.setSERVICE description()
#-------------------------------------------------------------------
# Call function to register eventlog message handler which is
# different if I'm a binary vs. PythonService.
#-------------------------------------------------------------------
self.getPythonS ervicePath()
#-------------------------------------------------------------------
# If this is a PythonService, point to installed PythonService.e xe
# if not, point to a copy of PythonService.e xe that gets installed
# along with the binary. Note: on binary distributions you must
# include a copy of PythonService.e xe along with your other files
# to provide EventLog message decoding.
#-------------------------------------------------------------------
if self.PythonServ ice: sourcepath=self .PythonServiceP ath
else: sourcepath=os.p ath.join(self.i nstallpath, "PythonService. exe ")
self.setSERVICE eventlogSource( sourcepath)
return

def getSERVICEtype( self):
'''
Function to determine if this is a Python service or a binary service
created by py2exe. Sets self.PythonServ ice=1 if it is a Python service
or PythonService=0 if it is a binary service.
'''
#---------------------------------------------------------------------
# This service can run as a PythonService or it can run as a binary
# .EXE service (created by py2exe). We can sense this by looking
# to see if
# HKLM\SYSTEM\Cur rentControlSet\ Services\_svc_n ame_\PythonClas s
# key exists in the registry. If it doesn't, then I'm a binary
# install.
#---------------------------------------------------------------------
# Open registry and search for PythonService install
#---------------------------------------------------------------------
regkey='SYSTEM\ CurrentControlS et\Services\%s' % self._svc_name_
key=_winreg.Ope nKey(_winreg.HK EY_LOCAL_MACHIN E, regkey)
nsubkeys, nvalues, lastmodified=_w inreg.QueryInfo Key(key)
#---------------------------------------------------------------------
# Begin by assuming I'm a binary (non-Python) service created by py2exe
#---------------------------------------------------------------------
self.PythonServ ice=0
#---------------------------------------------------------------------
# Loop over the keys in this branch looking for "PythonServ ice" key
#---------------------------------------------------------------------
for i in range(nsubkeys) :
subkeyname=_win reg.EnumKey(key , i)
if subkeyname == 'PythonClass':
self.PythonServ ice=1
break

return

def getSERVICEpath( self):
'''
Function to retrieve the full pathname to where the service has been
installed on the machine. This can be used to locate .INI or other
data files (if this service uses any).
'''
if self.PythonServ ice:
regkey='SYSTEM\ CurrentControlS et\Services\%s\ PythonClass' \
% self._svc_name_
value_name='' # Default
else:
regkey='SYSTEM\ CurrentControlS et\Services\%s' % self._svc_name_
value_name="Ima gePath"

#---------------------------------------------------------------------
# Get the contents of the value_name value under this key. This
# contains the full pathname where the service was installed and
# points me to the .INI file.
#---------------------------------------------------------------------
key=_winreg.Ope nKey(_winreg.HK EY_LOCAL_MACHIN E, regkey)
SERVICEpath=_wi nreg.QueryValue Ex(key, value_name)[0]
#---------------------------------------------------------------------
# Extract the full pathname where this service has been installed from
# this registry entry so I can locate the .INI file.
#---------------------------------------------------------------------
SERVICEpath=str (os.path.split( SERVICEpath)[0])
return SERVICEpath

def getPythonServic ePath(self):
'''
Function to retrieve the full pathname to where PythonService.e xe has
been installed on the machine (only used for Python Services, not binary
ones). This can be used to locate PythonService.e xe for EventLog
message decoding.
'''
self.PythonServ ice=None
regkey='SOFTWAR E\Python\Python Service'
try: key=_winreg.Ope nKey(_winreg.HK EY_LOCAL_MACHIN E, regkey)
except: return
#---------------------------------------------------------------------
# Get first subkeyname (Python Version)
#---------------------------------------------------------------------
subkeyname=_win reg.EnumKey(key , 0)
#---------------------------------------------------------------------
# Get the contents of the value_name value under this key. This
# contains the full pathname where the PythonService.e xe is installed.
#---------------------------------------------------------------------
self.PythonServ icePath=_winreg .QueryValue(key , subkeyname)
return

def setSERVICEdescr iption(self):
'''
This function sets the long description string that is displayed in the
Control Panel applet when this service is selected to the contents of
self._svc_descr iption_ defined at the top of the service.
'''
#---------------------------------------------------------------------
# Open registry at the proper key
#---------------------------------------------------------------------
regkey='SYSTEM\ CurrentControlS et\Services\%s' % self._svc_name_
key=_winreg.Ope nKey(_winreg.HK EY_LOCAL_MACHIN E, regkey, 0, \
_winreg.KEY_SET _VALUE)

_winreg.SetValu eEx(key, 'Description', 0, _winreg.REG_SZ, \
self._svc_descr iption_)
return

def setSERVICEevent logSource(self, sourcepath):
'''
This function sets the path to PythonService.e xe so that EventLog
messages can be properly decoded.
'''
win32evtlogutil .AddSourceToReg istry(self._svc _name_, sourcepath,
'Application')
return
Hope it helps,
Larry Bates

rbt wrote:
rbt wrote:
Roger Upole wrote:
ChangeServiceCo nfig2 is the api functions that sets the description,
but it's not in the win32service module (yet).

Roger


OK, I can use _winreg to add the 'Description' field under the
appropriate registry key.

Here's an example of it... kludgey but it works ;)

from _winreg import *
import time

def Svc_Description ():
try:
key_location = r"SYSTEM\Curren tControlSet\Ser vices\test_py_s ervice"
svc_key = OpenKey(HKEY_LO CAL_MACHINE, key_location, 0,
KEY_ALL_ACCESS)
SetValueEx(svc_ key,'Descriptio n',0,REG_SZ,u"B rad's Test Python
Service")
CloseKey(svc_ke y)
except Exception, e:
print e

Svc_Description ()
time.sleep(10)

Jul 18 '05 #5

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

Similar topics

2
1836
by: Larry Bates | last post by:
Anybody know what variable I need to define in my class to set the long description that shows up in the Services control panel applet? _svc_name_ holds the short name _svc_display_name_ holds the long name _svc_?????_ holds the description Thanks, Larry
3
2128
by: Matthew P. Seltzer | last post by:
All- This is a bit 'out there,' but, here goes. I have copied the WinSxS folder from a WinXP box to my Win2K box. I would like to be able to apply XP control styles to my Win2K VB.NET apps. Given what I have copied into my WinSXS folder, would I be able to use a combination of assembly manifests and isolated Win32 assemblies to do this? According to MSDN, comctl32.dll, Version 6, which is bundled with WinXP, is not redistributable. My...
2
3614
by: Ralph | last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2 installed, but I am having problems installing Visual Basic .net standard 2003. Not installing Visual Basic at the WinXP SP1A level - was the only way I found that I could install WinXPSP2. My computer was purchased with WinXP SP1 Professional. I also have Norton Internet Security and Norton...
3
2578
by: sparks | last post by:
I was copying fields from one table to another. IF the var name starts with milk I change it to egg and create it in the destination table. It works fine but I want to copy the description as well. Short version :) For Each fld In tdf.Fields pos = InStr(fld.Name, "milk") If pos > 0 Then
8
4004
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE( Pk_myPrimaryKey INTEGER CONSTRAINT pk PRIMARY KEY DESCRIPTION 'This is the primary key of the table',
2
1360
by: Per Rollvang | last post by:
Hi All! I am trying to figure out how to get info about different services from C#.NET. If I open the Services Applet from Control Panel (WinXP), I have an 'Extended Tab', whitch gives me a description-string, something I don't get using the framework's System.ServiceProcess.ServiceController object (among other things it don't seem to give me...).
2
7400
by: WRH | last post by:
Hello When I look at windows services with the Windows Administration tools Services utility (Win XP) I note that many services have a description field (2nd column). How can I add such a description for my service?
1
1624
by: Dave | last post by:
I wrote a C# windows service and it will install on Win2K but won't start. I have code in it to write to the event log but it doesn't log anything. I developed it on WinXP with VS and it installs and runs fine on that WinXP system. The service is a C# remoting listener if that makes any difference. Does it have to be built on a Win2K box to work correctly? I don't have VS installed anywhere but that WinXP so I can't readily test
0
1499
by: jcvoon | last post by:
Hi all: The application is a WinForm application which will invoke the Web Services host in the same development machine, the WSE policy is setup properly and it is configure to use usernameForCertificateSecurity policy. Same application work in WinXP with IIS5, but not work in Vista Business with IIS7, the following exception has been throw when invoke the web method Microsoft.Web.Services3.ResponseProcessingException was unhandled
0
9990
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11249
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9651
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5865
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4693
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3298
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.