windows-service.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 13 Jan 2015 11:26:27 +0200
changeset 1673 ed7fa7e54aaa
parent 1672 7a489de6fb71
child 1905 fba288d59662
permissions -rw-r--r--
About Windows services.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     1
.. -*- coding: utf-8; -*-
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     2
.. include:: HEADER.rst
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     4
==================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
 Windows service.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
==================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     7
.. contents::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
1673
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
     9
About Windows services.
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    10
=======================
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    11
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    12
  http://www.coretechnologies.com/WindowsServices/FAQ.html
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    13
    Windows Services Frequently Asked Questions (FAQ).
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    14
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
List services.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
==============
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
List of all running services::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    19
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
  cmd> net start
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
List of all services::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    24
  cmd> sc query
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    25
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
List of specific service::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    27
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
  cmd> sc query NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    29
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    30
GUI tool::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    31
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    32
  cmd> services.msc
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    33
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    34
Start/stop service.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    35
===================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
::
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    37
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
  cmd> net start NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
  cmd> sc start NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    41
  cmd> net stop NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
  cmd> sc stop NAME
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    44
  cmd> services.msc
1670
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    46
Create service.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    47
===============
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    48
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    49
In order to create service from any executable use ``srvany.exe`` from Windows
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    50
Resource Kits 2003 (take attention to spaces after ``=``)::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    51
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    52
  cmd> sc create NAME binPath= "c:\Program Files\Windows Resource Kits\Tools\srvany.exe" ^
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    53
       type= own start= auto error= normal DisplayName= "NAME for services.msc"
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    54
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    55
Then pass what ``srvany.exe`` wrapper to do::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    56
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    57
  cmd> reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NAME\Parameters" ^
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    58
     /v "Application" ^
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    59
     /d "\"c:\Program Files\Java\jre7\bin\java.exe\" -cp c:\home\devel\service Main"
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    60
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    61
Above you see quoting syntax for spaces and quotes. Next start service with::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    62
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    63
  cmd> sc start NAME
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    64
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    65
If you make error recheck your settings with::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    66
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    67
  cmd> reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\NAME" /s
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    68
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    69
Or remove service and make steps again::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    70
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    71
  cmd> sc delete NAME
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    72
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    73
Visit GUI ``services.msc`` and check with ``procexp.exe`` that service actually
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    74
do job.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    75
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    76
  http://www.microsoft.com/en-us/download/confirmation.aspx?id=17657
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    77
    Windows Server 2003 Resource Kit Tools download.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    78
  http://stackoverflow.com/questions/3663331/creating-a-service-with-sc-exe-how-to-pass-in-context-parameters
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    79
    How to pass parameters to sc.exe runnable.
1673
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    80
  https://support.microsoft.com/KB/137890
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    81
    How To Create a User-Defined Service (with Srvany.exe).
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    82
  http://technet.microsoft.com/en-us/library/cc990289.aspx
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    83
    Sc create help.
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    84
  http://support.microsoft.com/kb/251192
ed7fa7e54aaa About Windows services.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1672
diff changeset
    85
    How to create a Windows service by using Sc.exe
1671
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    86
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    87
Delete service.
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    88
===============
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    89
::
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    90
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    91
  cmd> sc delete NAME
ee48c908b156 Windows service.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1670
diff changeset
    92
1672
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    93
Service wrapper.
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    94
================
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    95
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    96
  http://en.wikipedia.org/wiki/Service_wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    97
    Service wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    98
  http://nssm.cc/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
    99
    NSSM - the Non-Sucking Service Manager
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   100
  http://sourceforge.net/projects/yajsw/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   101
    Yet Another Java Service Wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   102
  https://github.com/kohsuke/winsw/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   103
    A wrapper executable that can be used to host any executable as an Windows
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   104
    service
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   105
  http://code.google.com/p/simple-service-wrapper/
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   106
    Simple Windows Service Wrapper
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   107