mksrv

run program or script as service 

Command


SYNOPSIS

mksrv -install -name service_name [-displayname display_name] [-desktop | -username username [-password password]] [-verbose | -quiet] command_line

mksrv -install -displayname display_name [-name service_name] [-desktop | -username username [-password password]] [-verbose | -quiet] command_line

mksrv -remove -name service_or_display_name [-verbose | -quiet]

mksrv -debug -name service_or_display_name

mksrv -list

mksrv -RemoveAll


DESCRIPTION

The mksrv utility lets you run any program or script as a service.

To set up a program or script to run as a service, you must first use mksrv with the -install option (see Options) to cache the specified command_line (including program (or script) name and arguments), name it, and register it with the Service Control Manager. Windows services have two names: a service name and a display name. The service name is the name by which the service is known in the registry while the display name is a more descriptive name that appears in places like the Services pages of the Computer Manager. When setting up a program or script to run as a service, you must specify either or both of these names (specifying both is recommended). When you specify only the service name, that name is also used as the display name. When you specify only the display name, mksrv silently removes any spaces from that name and uses the result as the service name.

By default, when no -username option is given, the created service runs using the local system account. Also, by default, standard input, standard output, and standard error are not available unless they are redirected or the -desktop option is specified.

When specifying the command_line to be cached, you may need to quote the arguments passed at the end of the command line using normal quoting rules for the shell in use. For example:

mksrv -install -name MyService -displayname "My Service" -desktop "sh -c 'cd/tmp;ls'"

Once a service has been set up by the svsh utility, it can be started and stopped as desired with the MKS Toolkit control panel applet or with the service utility by referring to it using either the service or display name.

When a mksrv-created service is stopped (for example, with the service stop command), the child process for the service itself is killed, but any children created by that process are not.

Options

-debug 

Runs the service in debugging mode. In debugging mode, the service is run with a console window that lets you interact with it.

-desktop 

Tells the Windows Service Control Manager to let the service interact with the desktop through a console window. This option cannot be used with the -username option; only the local system account may interact with the desktop.

-displayname displayname 

Specifies the display name for the service being set up.

-install 

Sets up a program or script to be run as a service (see the DESCRIPTION section).

-list 

Displays the service names of all services registered using mksrv,

-name service_name 
-name service_or_display_name 

When used with -install, it specifies the service name to be used for the service being set up.

When used with -debug or -remove, it specifies either the service name or the display name of an already existing mksrv-created service.

-password password 

Can only be used with -username option to specify the password for the username account.

-quiet 

Directs status and error messages to the standard output, which is normally not visible unless redirected.

-remove 

Removes a mksrv-created service from the roster of services registered with the Service Control Manager.

-RemoveAll 

Removes all services registered using mksrv,

-username username 

Specifies the username whose account is to be used to run the service. username should also include the domain name when appropriate. You can specify the password associated with this account with the -password option. When no -password option is specified, mksrv prompts you to enter the associated password.

-verbose 

Displays a status window even if no error occurs.


EXAMPLES

The following commands set up the login version of the default shell to run as a service and start it:

mksrv -install -displayname "Shell as LocalSystem" -desktop $SHELL -L
service start "Shell as LocalSystem"

A new console window appears that is running using the local system account. The whoami utility can confirm this.


DIAGNOSTICS

Possible exit status values are:

0 

Successful completion.

>0 

An error occurred.


PORTABILITY

Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


AVAILABILITY

PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Commands:
service


PTC MKS Toolkit 10.4 Documentation Build 39.