![]() |
Writing True NT Services
with VB5
What?
Yes, its true, despite what you may have heard, you can create real NT Services with VB5. And its as simple as dropping a control on a form and writing your code. What makes this possible is a custom control written by Microsoft (appearing first in the Developer Network) which encapsulates all the necessary functionality of an NT Service into a custom control. The VB programmer is now freed from the hassle of mucking around with the registry and shipping srvany.exe and a .reg file with their program. The sample program includes code to install the service based on an '-install' command line option.
What's the catch?
The NT Service Control is technically a sample program and therefore not deserving of any Microsoft support (the only support you'll get is from me). I had to compile it myself (and fix a strange bug in it). What is annoying about the control is that it has to be bound to a form. While that would have been okay in 1993, I would rather be able to instantiate it as a code-only object, .i.e. 'CreateObject("NTService.NTService")' since a service has by definition, no user interface, why should i have to include a form in my project? That aside, it works well and seems very stable (much more stable than srvany) and of course you don't need to subclass your form to prevent windowstation-shutdown messages being misinterpreted, that's done for you.
Why wouldn't I want to use it?
If the service you were writing was sufficiently simple (ie it just did one thing and startup and basically sat idle for the rest of the time) and/or of sufficiently limited distribution (ie your 5-user workgroup) that you didn't need the advanced options of the NTService control, you should consider sticking with the srvany method. Also bear in mind that with the added functionality of this control comes additional complications, and if you don't need/want to be bothered with these, the previous method is probably still okay for you. This is definitely for Power Users.
Enough Waffle, let me download already
Okay, here we go:
ntsvrocx.zip: containing the following
\ntsvrocx.htm - the text of the original developer network article with hyperlinks+activeX removed
\readme.txt - a short intro of my own
\ntsrvocx\src - the orignal C++ source code
\ntsrvocx\src\release\ntsvc.ocx - the control itself
\ntsrvocx\sample - vb sample demonstrating many of the features
(Remember to unpack the archive with the directory structure intact, pkunzip -d, etc)
polkatulk@oocities.com
This page hosted by Get your own Free Home Page