Contents
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
Search
Login
Who Is Online?
We have 86 guests online
Navigation
Home Free Software Command line utilities ServiceExe - Install and run applications as Windows services
Most Recent
Featured Articles
Joomla 1.5 Featured Articles
Navigation
Home Free Software Command line utilities ServiceExe - Install and run applications as Windows services
English (United Kingdom)French (Fr)Deutsch (DE-CH-AT)
ServiceExe - Install and run applications as Windows services E-mail
User Rating: / 42
PoorBest 
Free Software - Command line utilities
Written by Thomas   
Thursday, 05 February 2009 17:22
Article Index
ServiceExe - Install and run applications as Windows services
License
Installation
The configuration file
Example configuration file
Configuration: The [General] section
Configuration: Process task sections
Embedded environment variables
Command line parameters
User credentials
Process logging
Common pitfalls
All Pages

 

ServiceExe can install Windows applications as Windows services. It works very similar to SrvAny from Microsoft and NSSM from Iain Patterson but doesn't have their disadvantages.


ServiceExe has been inspired by NSSM - the Non-Sucking Service Manager and derived from an unreleased application called File Copy Manager.

Unlike NSSM, ServiceExe can be run directly from the command line without additional keyboard or mouse input. It has no graphical user interface (GUI). This makes ServiceExe suitable for Windows service installations and removals from command line scripts.

ServiceExe can run Windows services

  • by running a single application as one single service.
  • by running several applications as one single service.
  • by running several applications as several different services.


NSSM and SrvAny use the Windows registry to store information about the services to install and run. ServiceExe uses a very simple and understandable configuration file for this purpose. No fiddling with the registry is required to use the software.

Applications run by SrvAny as a Windows service do not stop the actual service when they terminate or crash. This makes them look like actively working although they are not.

Applications run by older versionis of NSSM as a Windows service do not stop the actual service either. Instead, NSSM restarts them automatically. This had been a convenient task at the time when Windows NT was fashionate. From Windows 2000 onwards, all Windows versions support automatic restarts and actions to be taken if a service unexpectedly terminates. The latest version of NSSM supports these options too.

ServiceExe stops the Windows service if the application terminates and therefore hands over control to Windows again. If several applications are installed to run as one single service all applications belonging to the same service are automatically terminated. This avoids inconsistant states where some applications work fine while others don't. Once the service is started again all applications that belong to this service are started too.

The software can write extensive log files to help analyse issues. Everything it does can be logged.

Services can run under the LocalSystem account (default) or under any other user account. The user credentials can be provided via command line parameters.

ServiceExe supports further command line parameters to start the service optionally right after the installation and to set its start-up type to 'automatic'. Services with a start-up type of 'automatic' are automatically started when the system is rebooted (see dwStartType and SERVICE_AUTO_START at CreateService ().

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)



 

This software is provided "as-is", without any express or implied warranty.
In no event shall the author be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to redistribute it, provided that the following conditions are met:

1. The origin and any redistributions of the software must not be altered in any way.

2. All redistributions of this software and its files must retain all copyright notices that are currently in place, and this list of conditions without modification.

3. If you use this software within a product distribution, an acknowledgment in the product documentation would be appreciated but is not required.

4. This software comes without any support. Technical support is reserved for registered users only.

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)


 

The installation of ServiceExe is fairly simple but can vary depending on requirements and preferences.

A minimum run-time environment consists of only three files: The application ServiceExe, a configuration file, and an application which is supposed to run as the Windows service.

It is recommended to put these three files into the same folder, and that folder should not be used for anything else. Although technically not required it helps keep the installation tidy. ServiceExe's executable file ServiceExe.exe as well as the application that runs as the service will be locked throughout the service's run-time. That makes it impossible to rename or remove their parent folders.

The configuration file is a standard Windows configuration file (ini file). Its file name makes up the name of the Windows service.

<Installation folder>
ServiceExe.exe
<Service name>.ini    (Configuration file)
<My Application>.exe    (Application to run as a service)

Example installation:

C:\Program files\MyService
ServiceExe.exe
MyService.ini            (Configuration file)
MyApplication.exe        (Application to run as a service)

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

Configuration files for ServiceExe are standard Windows configuration files (ini files). They consist of a [General] section and an additional section for each process/application to run.

MyService.ini:

[General]
ServiceDisplayName=My own service
ServiceDescription=This is my own service
StartUpPause=1
CreateProcessPause=1
LogPath=Logs
ServiceProcesses=App1

[App1]
ApplicationName=MyApplication.exe
CommandLine=
CurrentDirectory=

The ini file's name without file name extension declares the name of the Windows service. The Windows Services Panel shows it as 'Service Name' on the properties page and is identical to the parameter lpServiceName of CreateService ().

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 




Open ServiceExeTest.ini
 

ServiceExeTest.ini:

; ***************************************************************************
;
; Example configuration file for ServiceExe.exe
;
;
; History
;
; When      Who          What
; ---------------------------------------------------------------------------
; 2008-02-04  Thomas        Created.
; 2010-09-27  Thomas        Updated for different fail strategies.
;
; ***************************************************************************
 
[General]
 
; The service's name to display.
;  The service name (not the display name) is the name of the ini file.
ServiceDisplayName=Testing ServiceExe
 
; The service's description.
ServiceDescription=This is our new service
 
; Time in seconds to wait before the processes are
;  started.
StartUpPause=1
 
; Time in seconds to wait between each process to
;  start.
CreateProcessPause=1
 
; Path to the log files. If this is not given, the application's
;  (executable file's) path is assumed. Note that this will not work
;  without changing the permissions accordingly.
 
LogPath=Logs
 
; Lists all the sections of the processes, separated by blanks.
ServiceProcesses=Process1
 
[Process1]
ApplicationName=%ComSpec%
CommandLine=/C Test.cmd
CurrentDirectory=
 
; Specifies the behaviour in case the process terminates or its
;  creation fails. Default is behaviour 0.
;
;  0 = The service stops, terminating all processes that belong to it.
;       Use this for Windows command line applications.
;  4 = The service stops, ending all processes that belong to it by
;       sending WM_QUIT messages to their windows. Use this for
;       Windows GUI (graphical user interface) applications.
FailStrategy=0
 
Open ServiceExeTest.ini


To test the file, invoke ServiceExe with the following parameters:

ServiceExe.exe -console ServiceExeTest.ini

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

[General]

This section contains the general settings for the Windows service.

ServiceDisplayName=<string>

The display name of the service is what the Windows Services Panel shows in the 'Name' column. On its properties page it is called 'Display name'. This is also identical to the parameter lpDisplayName of CreateService ().

ServiceDescription=<string>

A short description for the service. On Windows Services Panel's properties page this is called 'Description'. Although there does not seem to be a restriction on Windows, ServiceExe only accepts the first 499 characters of the service's description.

StartUpPause=<value>

After ServiceExe has been invoked StartUpPause specifies a pause time in seconds for the software to wait before the service tasks are started. This can speed up the time a machine reboot takes if set to an appropriate value. The default value is 0 seconds, meaning that ServiceExe will start the defined service process(es) as soon as it has been started itself.

CreateProcessPause=<value>

This value is similar to StartUpPause with the exception that it specifies the pause time after a new process has been created. If ServiceExe has to start many applications (processes) a delay after each process has been created can reduce the overall time it takes for the system to have all of them finally up and running. The default value is 0 seconds. This means that ServiceExe will not pause after it has created a new process.

LogPath=<path string>

If ServiceExe works with the logging DLL logtext.dll this key provides a folder name where the software can store log files. The default folder for log files is the folder where ServiceExe.exe itself resides. The string <path string> supports embedded environment variables. More information on process logging with ServiceExe and Logtext can be found at Process logging.

ServiceProcesses=<process1> [<process2>] [<process3>] ...

This lists all service process tasks. Each application that is supposed to run as a Windows service by the same ServiceExe requires its own process task section in the configuration file.

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

Each process task listed in ServiceProcesses in the [General] section requires its own process task section in the configuration file.

ApplicationName=<path string>

This is the full name and path of the application to run as a Windows service. If 'ApplicationName' contains relative path information the base folder is the folder in which ServiceExe.exe itself resides. The string <path string> supports embedded environment variables.

Examples:

ApplicationName=C:\Program files\MyApplication\MyApplication.exe
ApplicationName=MyApplication.exe

By utilising the correct settings for 'ApplicationName' and 'CommandLine' it is also possible to install and run Windows command line scripts as Windows services.

CommandLine=<parameter string>

The command line parameters for the application specified with 'ApplicationName'. The default is an empty string, i.e. no parameters are passed to the application.

By utilising the correct settings for 'ApplicationName' and 'CommandLine' it is also possible to install and run Windows command line scripts as Windows services.

The following example installs and runs the command line interpreter CMD.EXE as a Windows service. When the service is started, the command line script MyBatchFile.cmd is executed. When MyBatchFile.cmd terminates the entrie service stops.

ApplicationName=%ComSpec%
CommandLine=/C MyBatchFile.cmd

CurrentDirectory=<string>

ServiceExe sets the current working directory for the application supposed to run as a service to the string provided with 'CurrentDirectory'. This setting supports embedded environment variables. The default is the folder/directory in which ServiceExe.exe itself resides.

Examples:

CurrentDirectory=C:\Program files\MyApplication
CurrentDirectory=%windir%
CurrentDirectory=%TEMP%

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

Some configuration settings support embedded environment variables. These settings are:

- LogPath
- ApplicationName
- CommandLine

The syntax for using environment variables is identical to their usage in Windows command line scripts. Variables are embedded by surrounding their names in '%' characters, like '%variable%'.

Examples:

LogPath=%APPDATA%\Logs
ApplicationName=%ComSpec%
CommandLine=%USERPROFILE%

Environment variables in ServiceExe's configuration files can provide more flexibility.

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

ServiceExe provides the following command line parameters:


Invocation:
ServiceExe -install inifile <params>   to install the service
ServiceExe -remove inifile <params>    to remove the service
ServiceExe -debug inifile <params>     to run as a console app for debugging
ServiceExe -console inifile <params>   same as -debug

<params>:
/A            Set service start type to automatic.
/S            Start the service after installation.
/U:username   Use this account instead of the local system
account.
/P:password   Password for account /U:username.


All command line parameters are case-sensitive, for instance '-Install' or '-INSTALL' will *not* work. See 'Example configuration file' for an example on how to use the command line parameters.

inifile

This is a placeholder for a configuration file. The file name must be provided including the file name extension. See 'Example configuration file' for an example on how to provide a configuration file parameter.

-install

Installs (registers) the applcation as a Windows service. After a successful installation the service is visible in the Windows Services Panel and can be started, stopped, etc, for there. If no user credentials are provided (/U: and /P: parameters) the service is installed to run with the credentials of the LocalSystem account. If credentials are provided the service is installed to work with these credentials. If the user specified with the /U: parameter doesn't have the right to log on as a Windows service yet this right is automatically given to him during the installation process. See 'User credentials' for some common pitfalls.

- remove

Uninstalls (unregisters) the application as a Windows service. If the service has been running (started) it is stopped first.

On Windows 2000 it is recommended that the Services Panel is not open when the service is removed. Windows 2000 has a bug that sometimes prevents the service from being removed without a system restart. This seems to have been fixed on newer versions of Windows like Windows XP and the 2003 series of servers.

- console
- debug

Runs the application in a test mode which allows to check that the configuration and file system structure has been set up correctly. It is recommended to use this option for some time before finally installing the service with -install. The parameters -console and -debug ignore any user credentials provided with /U: and /P:. The application always runs under the account of the current user. See 'User credentials' for some common pitfalls. The application is started immediately even without the /S parameter. Since no service is installed the /A parameter is ignored too.

/A

Marks the service as 'Automatic'. This ensures that the system attempts to start the service automatically after a system reboot.

/S

Attempts to start the service immediately after installation.

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

ServiceExe accepts user credentials as command line parameters with the /U: and /P: parameters.

/U:<domain\>username

Specifies the user name for the service to run as. If the user is part of a domain the domain's name must go in front of the user name. No white space is allowed between the /U: parameter and the domain/user name. If the given user does not have the right to log on as a Windows service yet this right is automatically given to him. Windows user names are not case-sensitive.

If /U: is provided a /P: parameter must be provided too. ServiceExe is not going to ask for a password if no /P: parameter exists. However, if no /P: parameter is given the password can still be entered in the Windows Services Panel later. Incorrect user credentials will fail to start the Windows service.

The /U: as well as the /P: paramer is ignored when the application is run in test mode (-console or -debug). In test mode, the applcation always runs under the current user account but does not report an error. This is so that as little as possible in the command line needs to be changed for switching between test mode and production mode.

/P:password

The password for the user name provided with the /U: parameter. Windows passwords are case-sensitive.

If a password is specified with the /P: parameter but no /U: parameter exists the /P: parameter is ignored.

Examples:

ServiceExe.exe -console ServiceExeTest.ini /S /A /U:username /P:password

Runs the application specified in the key 'ApplicationName' of the configuration file ServiceExeTest.ini with the credentials of the user currently logged on (-console). The application is started immediately, but not because of the /S parameter but rather because of -console. The command line parameters /S, /A, /U:, and /P: are entirely ignored.

ServiceExe.exe -install ServiceExeTest.ini /S /A /U:username /P:password

Installs the application specified in the key 'ApplicationName' of the configuration file ServiceExeTest.ini as a Windows service (-install). Before it starts the service (/S) with the credentials of user 'user' (/U: and /P:) ServiceExe ensures that the user has the right to log on as a Windows service. The service is marked to start up automatically after a system reboot (/A).

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

ServiceExe can use the Logtext direct link library for process logging. Without Logtext, ServiceExe cannot log anything. ServiceExe comes with a newer version of logtext.dll than Logtext's website provides.

 

Logtext.dll requires a configuration file itself, logtext.ini, so make sure you copy at least the DLL and the configuration file into the same folder as ServiceExe.exe. Both files are included in the ServiceExe package.

 

Save both files in the same directory with ServiceExe.exe and its configuration file. In ServiceExe's configuration file the key 'LogPath' in the [General] section tells the software where to store process logging information. It goes without saying that ServiceExe needs write access to that folder.

 

Note that this logging folder ("LogPath") is not created automatically. The folder must exist prior to be used by ServiceExe and Logtext.

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 


 

One common pitfall with ServiceExe is when the application has been tested with -console or -debug, but then does not work as intended when installed as a service. For example, if no logging information is stored in the intended log path (configuration file, section [General], key 'LogPath'), this is an indication for that issue. The user account that runs the service is most likely responsible for this misbehaviour.

ServiceExe -console ServiceExeTest.ini

Runs the application specified in the key 'ApplicationName' of the configuration file ServiceExeTest.ini with the credentials of the user currently logged on (-console). The application is started immediately.

ServiceExe -install ServiceExeTest.ini

Installs the application specified in the key 'ApplicationName' of the configuration file ServiceExeTest.ini as a Windows service. When started, the service runs with the user credentials of the account LocalSystem.

If LocalSystem does not have appropriate permissions to access all required resources, the service seems not to work properly, which includes:

- Registry keys/values cannot be accessed.
- The file system cannot be accessed, for instance log files cannot be written.
- Network access is denied.

The solution is to either provide appropriate permissions for LocalSystem or run ServiceExe under an account that has the required permissions. The parameters /U: and /P: or the Windows Services Panel can assist here.

 

Download ServiceExe.zip (0.11 MiB = 108.4 KiB = 111,041 bytes)

 

Last Updated on Thursday, 05 July 2012 13:25
 
You need to login or register to post comments.
Discuss this item on the forums. (0 posts)
Discuss (0 posts)