windows-service.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 10 Feb 2018 01:36:16 +0200
changeset 2229 1a0b6597e594
parent 2228 837f1337c59b
child 2247 91816f9ab872
permissions -rw-r--r--
Mark block quot in HTMLe.
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
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
 Windows service.
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     5
==================
c7c98a85c749 Windows services from command line.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     6
.. contents::
1905
fba288d59662 Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1673
diff changeset
     7
   :local:
1670
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
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    12
http://www.coretechnologies.com/WindowsServices/FAQ.html
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    13
  Windows Services Frequently Asked Questions (FAQ).
1673
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
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    76
http://www.microsoft.com/en-us/download/confirmation.aspx?id=17657
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    77
  Windows Server 2003 Resource Kit Tools download.
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    78
http://stackoverflow.com/questions/3663331/creating-a-service-with-sc-exe-how-to-pass-in-context-parameters
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    79
  How to pass parameters to sc.exe runnable.
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    80
https://support.microsoft.com/KB/137890
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    81
  How To Create a User-Defined Service (with Srvany.exe).
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    82
http://technet.microsoft.com/en-us/library/cc990289.aspx
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    83
  Sc create help.
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    84
http://support.microsoft.com/kb/251192
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
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
2228
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    96
http://en.wikipedia.org/wiki/Service_wrapper
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    97
  Service wrapper
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    98
http://nssm.cc/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
    99
  NSSM - the Non-Sucking Service Manager
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   100
http://sourceforge.net/projects/yajsw/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   101
  Yet Another Java Service Wrapper
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   102
https://github.com/kohsuke/winsw/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   103
  A wrapper executable that can be used to host any executable as an Windows
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   104
  service
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   105
http://code.google.com/p/simple-service-wrapper/
837f1337c59b Removed indentation that compiled into <blockquote>.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1912
diff changeset
   106
  Simple Windows Service Wrapper
1672
7a489de6fb71 Service wrapper.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 1671
diff changeset
   107