NT Service Sample

This sample is located in \Samples\Com\NTService.

Note   To use this sample, it is recommended that you have Microsoft® Visual C++® version 5.0 or higher installed.

Description
Using the Sample
Key Project Files
Technologies Demonstrated

Description

These samples show how to build a Microsoft® Windows NT® Service using only Java, implementing the Service Main and Service Control as Java classes. They also show how to use the Windows NT Event Log with a custom message file.

The DCOM Server serves a Java-implemented COM object that is created in a single-threaded apartment. A WFC applet and an AWT-based applet have been created that use a Microsoft® J/Direct™ call to CoCreateInstanceEx to instantiate the served COM object remotely, without any local registry settings or installation.

The DCOM client applications are provided for connecting to the Windows NT Service. They show how to specify Proxy Security settings on COM objects from Java using a J/Direct call to CoSetProxyBlanket.

The same Windows NT Service can also be built using the Jtnsvc.exe tool and the com.ms.service classes from the Microsoft SDK for Java.

DCOM Client The AWT applet and WFC application. These are stand-alone clients that create an instance of the served COM object.
DCOM Server COM Server classes that use the base Windows NT Service implementation from \Samples\Com\NTService\Sample\Ntservice and use the COM Server, single-threaded apartment, and COM method functionality from the \Samples\Com\NTService\Sample\Dcom package. TestService.java is an implementation of the same Windows NT Service using the com.ms.service and Jntsvc.exe tool.

Using the Sample

To compile the complete version of the custom messaging sample

  1. Build Windows NT Service by running the makefile in the current directory. This compiles the Java files and creates NTService.exe, the Client.exe WFC application, and the COMClient.cab file used by Client.htm to implement the AWT applet client.

  2. Register the Windows NT Service on the local computer using NTService.exe /install.

  3. Run Dcomcnfg.exe, select A Java Service! from the list of applications, and choose Properties. Under the Security tab, modify the list of users allowed access to include those that you want to allow access to the served COM object. Only these users' security credentials will allow the clients to work correctly.

  4. Run Dcomcnfg.exe and select the Default Properties tab. Ensure that Enable Distributed COM on this Computer is checked. Set the Default Authentication Level and Default Impersonation Level options to the required level. The client application will need to specify Authentication and Authorization levels.

  5. Run any of the clients, specifying the server name of the computer where the Windows NT Service is installed and the credentials/security information according to the settings you made using Dcomcnfg.exe.

The Windows NT Service consists of the Java classes that are the actual service implementation, and the Message resources that are required for writing events to the event log.

Another way of creating the Windows NT Service is to use Jexegen.exe to bundle the Java classes into an .exe file, and then using Jexegen.exe to bundle the resources into a separate .dll file. This keeps the messages separate from the executable.

By default, the makefile in \Samples\Com\NTService builds the messages in a separate .dll file. However, you can specify how you want the service built.

To build the DLL version, run the following command:

NMAKE DLL

To build the executable version, run the following command:

NMAKE EXE /f makefileVC

To compile the com.ms.server /jntsvc version of the Custom Messaging sample

The Windows NT Service built with jntsvc is essentially the same as the other version, except that the custom messaging file is not available, and a separate batch file is required for registering the COM object being served.

  1. Run the Buildjntservice.bat file in the current directory. This compiles the Java files and generate the TestService.exe.

  2. Register the Windows NT Service on the local computer using NTService.exe /install.

  3. Run Jntregister.bat to add the COM settings to the registry. This is not required for the other Windows NT Service implementation.

  4. Run Dcomcnfg.exe, select A Java Service! from the list of applications, and choose Properties. In the Security property page, modify the list of users allowed access to include those that you want to allow access to the served COM object. Only these users' security credentials will allow the clients to work correctly.

  5. Run Dcomcnfg.exe and select the Default Properties property page. Be sure that Enable Distributed COM on This Computer is checked. Set the default Authentication Level and default Impersonation Level options to the required level. The client application will need to specify Authentication and Authorization levels.

  6. Run any of the clients, specifying the server name of the computer where the Windows NT Service is installed, and the credentials/security information specified with Dcomcnfg.exe.

Key Project Files

\Samples\Com\NTService\Sample\Dcom\*.java

This directory contains generic helper classes that call COM functions, provide Java/COM wrappers for IClassFactory, and provide Java implementations of C structures required by CoCreateInstanceEx.

\Samples\Com\NTService\Sample\NTService\*.java

This directory contains implementations of the generic Windows NT Service base class and all the Java-implemented C structures required for calling the appropriate Microsoft® Win32® API functions.

StructArray.java

This class is used for dealing with arrays of Java-implemented C structures.

Technologies Demonstrated

Microsoft J/Direct

This sample shows how to use:

COM

This sample shows how to:

Windows NT Service

This sample shows how to:

© 1999 Microsoft Corporation. All rights reserved. Terms of use.