Notes on using command line arguments with the Windows Service Manager - A4000037 - 19 May 2008

Typically customisation of the DP4 service is handled by making changes to DP4.INI. Some users have expressed the desire to be able to have an identical DP4.ini on machines in which the DP4 service is started in differing configurations, and have tried to achieve this by modifying the registry settings for the DP4 service to include command line options. This article explains how command line parameters work with Windows services. Much of the content of this article applies to all services, and not just to the DP4 service. If you want to use this technique you will require an srvw32.exe with a build number of 188 or later. This was incorporated into the "623beta" set as of 19th May 2008.

There are two types of Windows service process: services which have a dedicated process (such as the "Distributed Transaction Coordinator"), and services which are hosted by a process such as svchost which runs several services (most of the services provided by Microsoft on Windows XP).

Because of this, service processes are passed two sets of command line arguments: one set is passed when the process for the service is started. A second set is passed when the service itself is started. The most obvious way of passing this second set of arguments is to open the Properties dialog for a service within services.msc (the Control Panel applet for services with Administrative tools), and to specify values in the "start parameters" edit box. For some reason it is not possible to save a set of "start parameters" which will be used each time the service is started. A second method of passing this second set of parameters is to use net start. For example "net start servicename /test" will pass the command line argument "/test" to the specified service. However, this option cannot be used with the DP4 service because net start only allows options to be specified with a /, and DP4 only understands Unix-style options beginning with -. If one examines the properties dialog for a number of services it will be found that command line options can also be passed as part of the "Path to executable" setting for the service. This cannot be edited, and is normally created when the service (or Windows) is first installed. It is taken from the value of the ImagePath setting for the service. Thus, for DP4 it would typically be in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\dfSolutions or HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\ItimDP4 (depending on how your DP4 configuration is branded). This set of arguments is passed when the process for the service is started. Thus it would not be appropriate to pass service specific options here for a "hosted" service. (N.B. The fact that arguments can be passed in ImagePath was not documented until Windows XP was released, but this method was supported in Windows 2000 as well (and probably NT4)).

Prior to build 188, the DP4 service would not respect arguments specified in the ImagePath setting, at least prior to Windows Vista. The reason for this was that when the ServiceMain entry point was called any arguments specified on the command line that had not already been processed were thrown away and only the arguments passed to ServiceMain were respected. srvw32 will now respect these arguments, assuming that DP4 is either being started from the control panel, started automatically at boot time, or started with net start. To DP4 it would appear that these arguments had been passed on the command line, so that they take precedence over the defaults specified within dp4.ini. However, when DP4 is started manually with srvw32 -start, whether from a command line prompt, or when DP4 is auto-loaded, then whether or not these arguments are respected depends on the other arguments passed to srvw32 -start. The rule is as follows:

Thus, one could arrange for machines with identical DP4.INI files to start DP4 differently on each machine by setting -startup=xxx -preload=yyy as part of the ImagePath setting. In order to do this it will be necessary to modify the ImagePath setting after running srvw32 -install. It would not be a good idea to omit running srvw32 -install, or to replace the entire group of settings for the DP4 service since the settings might vary depending on the version of Windows being used on each machine.

srvw32 will now report both sets of command line options passed to it (assuming some arguments are passed), and will report which set of arguments is being respected.

On no account specify any of the following options in the ImagePath section: -start, -stop, -load, -unload. Use of any of these options will prevent the DP4 service from loading correctly.