Microsoft SDK for Java

Jntsvc Usage Notes

The Microsoft SDK for Java provides the following support for writing Windows NT system services:

For information on writing Microsoft® Windows NT® system services in Java, see the com.ms.service package.

The jntsvc tool generates a service executable. It is similar in usage and purpose to the jexegen tool. The use of the command file and specification of the class files in combination with the /base and /r options are identical to those used with jexegen.

Service Example

The following command line generates an executable for the test service included with the SDK for Java:

jntsvc /svcmain:TestService /eventsource:TestService
   /base:%SDKDIR%\bin\jntsvc TestService.class

In this example, %SDKDIR% is the SDK for Java directory.

Generating Version 2 Format Resources

Jntsvc (like jexegen) now generates version 2 format resources which can contain arbitrary data files. To add arbitrary files, use the same jntsvc syntax as for class files. For example:

jntsvc /svcmain:MyService /out:MyService.exe MyService.class MyService.dat

If jntsvc encounters a file that is not a class file (in this example, MyService.dat), it automatically generates a version 2 format resource.

Note that unlike jexegen, jntsvc does not have a /maxver option that can be specified to force the use of version 1 format resources.

Installing, Uninstalling, and Running the Executable

After you have generated the executable, use the following command line to install, uninstall, or run the executable:

<executable name> [options] [arguments to service]

For example the following commands install and uninstall MyService:

MyService /install
MyService /uninstall

See the table below for a description of the available options.

If the service class has methods of the form:

static void installService(String PackagedParams, String UserParams)

and/or:

static void uninstallService()

then these methods will be invoked when the service is installed or uninstalled, respectively. This allows the service to programmatically specify any custom settings on the machine. The service executable can then be a distribution unit instead of being packaged as a cab file.

The installService method's parameters come from two sources:

The following table briefly describes the available options for installing, uninstalling, and running a service:

/install Installs the service.
/uninstall Uninstalls the service.
/cmd:<service name> Runs the service <service name> in command-line mode. This is useful when starting and controlling a service under a debugger. Messages that are normally sent to the event log are sent to the console. Service events can be simulated by entering the following commands in the console window:

Note   /cmd is not available for windowed services.

  • STOP
    Sends a SERVICE_CONTROL_STOP event to the service.

  • PAUSE
    Sends a SERVICE_CONTROL_PAUSE event to the service.

  • CONTINUE
    Sends a SERVICE_CONTROL_CONTINUE event to the service.

  • SHUTDOWN
    Sends a SERVICE_CONTROL_SHUTDOWN event to the service.

  • INTERROGATE
    Sends a SERVICE_CONTROL_INTERROGATE event to the service.
/debug Displays additional diagnostic information. When used with /install, it pauses before installing each service.
/rename:<old name>=<new name> Sets the service's name at install time. This option can be used to install a service multiple times from the same executable, with each instance of the service having a different name and running in a separate process. This option can also be used to rename a service without regenerating the executable.

For example, if a service is built with the following command:

jntsvc /out:MyService.exe /svcmain:MyService MyService.class

then the service can be installed with a different service name using the following command:

MyService /install /rename:MyService=MyService2
/params:<parameters> Specifies the parameters that are provided to the service as the UserParams parameter in its installService method. If none are specified, an empty string ("") is used.

The service receives both the parameters specified when the service executable was generated (using the /installparams option to the jntsvc /svcmain switch) and the parameters specified at install time using this /params option.

/username:<user name> Specifies the account the service runs as. The default value is LocalSystem. This option cannot be specified for multiple-service executables.
/password:<password> Specifies the password for the user name.
/quiet Completely suppresses the user interface, including console output.

Important Note    As of version 2.02, the service information is contained within the generated executable. Therefore, the registry keys under HKLM\System\CurrentControlSet\Services that were used for version 1.5.1 services are no longer recognized. In version 1.5.1, certain parameter values were specified when the svcsetup was run. However, with version 2.02, to change the values of these parameters you must regenerate the executable. The only exceptions to this rule are the /password and the /username parameters, which are now options that you can specify on the generated executable.

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