FILE: HELSVC.EXE Implements an OLE Server in a Service
This article was previously published under Q156673 On This PageSUMMARY The HELSVC sample is a simple OLE Automation server
implemented in a service called "Hello OLE Server
Service." The following file is available for download from the Microsoft Download Center: Helsvc.exe (http://download.microsoft.com/download/ole/helsvc/2000/nt45/en-us/helsvc.exe) For
additional information about how to download Microsoft Support files, click the
following article number to view the article in the Microsoft Knowledge Base: 119591 (http://support.microsoft.com/kb/119591/EN-US/) How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most
current virus-detection software that was available on the date that the file
was posted. The file is stored on security-enhanced servers that help to
prevent any unauthorized changes to the file.
MORE INFORMATION This server implements one application object with a dual
interface. It also registers the application object in the RunningObjectTable
so that any client can access it. The sample includes a Visual Basic client
that can control the server. The sample does not use any framework such as MFC,
ATL, etc. Implementation NotesNT 4.0 removes the limitations of using OLE in services that are described in the following article in the Microsoft Knowledge Base:149571 (http://support.microsoft.com/kb/149571/EN-US/) Using OLE in Services in Windows NT 3.51
For an overview of implementing an OLE server in a service in NT
4.0 and later versions, read the following topics in the Win32 SDK Online
documentation:
"LocalService" To find these topics, query using the LocalService
keyword."Installing as a Win32 Service or User Account" When the service starts, it registers a multiple-use class factory. It then registers an object in the Running Object Table using ROTFLAGS_ALLOWANYCLIENT, which allows clients in any security context to bind to the object using IRunningObjectTable::GetObject or GetActiveObject (if the appropriate permissions are specified in the server's access permissions using the DCOMCNFG tool). If ROTFLAGS_ALLOWANYCLIENT is not used in the ROT registration, only clients in the same security context as the server will be able to bind to it. RegisterActiveObject currently does not support ROTFLAGS_ALLOWANYCLIENT, so the sample provides a new function, MyRegisterActiveObject, which supports this flag. IRunningObjectTable::Register supports this flag. Registration using this flag requires a registry entry similar to the following to prevent a CO_E_WRONG_SERVER_IDENTITY error:
[HKEY_CLASSES_ROOT\APPID\helloservice.exe]
"APPID"="{0bf52b15-8cab-11cf-8572-00aa00c006cf}"
Because of a bug in NT 4.0, Build 1381, registration using
ROTFLAGS_ALLOWCLIENT is always weak, even if ROTFLAGS_REGISTRATIONKEEPSALIVE is
also specified. As a consequence, the ROT will release its reference on the
object when the last client releases its reference and clients that are
launched later will not be able to bind to the running object. A workaround is
for the server to place a strong lock on the registered object using
CoLockObjectExternal while it is in the ROT.NOTE: The bug mentioned in the paragraph above has been fixed in NT 4.0, Service Pack 2. See the .reg file for information of the registry entries used by the service. Many services are debugged by running them as console applications in the interactive user's identity. For example, this sample service can be debugged by running it as follows:
helloservice -debug
Because the service is already registered to run in a different
identity (configurable by the Services control panel applet), OLE will fail
CoRegisterClassObject and
IRunningObjectTable::Register(ROTFLAGS_ALLOWANYCLIENT) by returning
CO_E_WRONG_SERVER_IDENTITY to enforce security and to prevent malicious servers
from spoofing the server. To debug by running in the interactive user's
identity, make the following changes in the server's registry entries to
prevent these failures:
To CompileNT 4.0 or later is required. To compile, type:
nmake To compile a version without debug information and without
message boxes that are displayed to indicate progress or failure, type:
nmake DEBUG=0 To Run
FilesSERVICE.C & SERVICE.H have the code to create a service and are copied from the SERVICE sample in the WIn32 SDK. (See the comments in service.h for information on command line arguments accepted by the service.)MAIN.CPP and HELLO.CPP implement the automation object. HELLOCF.CPP implements the class factory. HELLO.ODL is the object description language that describes the property and methods that HELLO exposes. TLB.H is the header file generated by MIDL. MAKEFILE is the Makefile for project. HELLO.REG is the Registry information. APPLIES TO
| Article Translations
| |||||||||||||||||||||||||||||||||||||||

Back to the top
