{"id":41351034,"url":"https://github.com/mturk/svcbatch","last_synced_at":"2026-01-23T07:19:20.441Z","repository":{"id":37477800,"uuid":"293802139","full_name":"mturk/svcbatch","owner":"mturk","description":"Run batch files as Windows service","archived":false,"fork":false,"pushed_at":"2024-04-30T16:16:39.000Z","size":1874,"stargazers_count":20,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-30T17:30:36.531Z","etag":null,"topics":["batchfile","log-rotation","windows-service","windows-services"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mturk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-09-08T12:22:41.000Z","updated_at":"2024-04-30T16:16:43.000Z","dependencies_parsed_at":"2023-11-12T00:20:20.241Z","dependency_job_id":"886ef5b8-3d38-4fa0-a991-26b9648f9f54","html_url":"https://github.com/mturk/svcbatch","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/mturk/svcbatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mturk%2Fsvcbatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mturk%2Fsvcbatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mturk%2Fsvcbatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mturk%2Fsvcbatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mturk","download_url":"https://codeload.github.com/mturk/svcbatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mturk%2Fsvcbatch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28682847,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batchfile","log-rotation","windows-service","windows-services"],"created_at":"2026-01-23T07:19:19.919Z","updated_at":"2026-01-23T07:19:20.435Z","avatar_url":"https://github.com/mturk.png","language":"C","readme":"# SvcBatch: Overview\n\nSvcBatch is a program that allows users to run script files as Windows service.\n\nThe program's main goal is to run any application as a Windows\nservice by using a batch file wrapper as an application launcher.\nThis is particularly useful when running Java applications or\nfor scripts written in Perl, Python, Ruby, etc... without the need\nfor a specialized service wrapper.\n\nSvcBatch was designed to be simple to use and lightweight, with a small\nmemory footprint. Its only dependency is win32 API, and only has\naround 8K lines of **C** code. There are no configuration\nfiles or installation requirements, so it can be easily distributed\nalongside any application that requires Windows service functionality.\n\nRead the rest of the documentation and check [Examples](#examples)\nfor some overview and ideas how to use and deploy SvcBatch\nwith your application.\n\n* Github: [https://github.com/mturk/svcbatch](https://github.com/mturk/svcbatch)\n* Docs: [Documentation](docs/index.md)\n\n# Table of Contents\n\n- [SvcBatch: Overview](#svcbatch-overview)\n- [Table of Contents](#table-of-contents)\n- [Getting Started](#getting-started)\n  - [Supported Windows Versions](#supported-windows-versions)\n  - [Building SvcBatch](#building-svcbatch)\n  - [Creating Services](#creating-services)\n  - [Managing Services](#managing-services)\n  - [Debugging Services](#debugging-services)\n- [Examples](#examples)\n- [Main Features](#main-features)\n  - [Log Rotation](#log-rotation)\n  - [Command Line Options](#command-line-options)\n  - [Private Environment Variables](#private-environment-variables)\n  - [Stop and Shutdown](#stop-and-shutdown)\n  - [Version Information](#version-information)\n  - [Error Logging](#error-logging)\n- [Limitations](#limitations)\n- [License](#license)\n\n# Getting Started\n\n## Supported Windows Versions\n\nThe minimum supported version is *Windows 7 SP1* or\n*Windows Server 2008 R2* 64-bit.\n\n\n## Building SvcBatch\n\nTo build the SvcBatch from source code follow the\ndirections explained in [Building](docs/building.md) document.\nSvcBatch is targeted for Windows 64-bit versions, so make sure\nto use 64-bit compiler.\n\n## Creating Services\n\nStarting with version **3.0.0** SvcBatch has a Service management\ncode that contains a subset of Microsoft's `sc.exe` utility to\ncreate, configure, manage, and delete services.\nCheck the [managing](docs/manage.md) section for some basic\nguidelines.\n\nBy default SvcBatch uses System's `cmd.exe` as a shell to run a batch file.\nThus the batch file is an *actual* service application from a\nconceptual point of view.\n\nThe batch file should behave like a *service* and must never\nexit. Any exit is treated as an error because from the SCM\n(Service Control Manager) point of view it is the same\nas a service failure. On Stop or Shutdown events signaled\nby SCM, SvcBatch will send a CTRL_C signal to cmd.exe, as\nif a user hit Ctrl+C keys in interactive console session.\n\nThe simplest way to create a service for your batch file\nis to put `svcbatch.exe` in the same directory where your\n`myservice.bat` file is located. Open the command prompt and\ntype something like this...\n\n```no-highlight\n\u003e svcbatch create myservice\n\n```\n... or using `SC` utility\n\n```no-highlight\n\u003e sc create myservice binPath= \"\"%cd%\\svcbatch.exe\" myservice.bat\"\n\n```\n\nCheck [Examples](#examples) section for more\ndetailed usage.\n\n\n* **Modifying services**\n\n  Once installed you can edit the **ImagePath** value\n  from the service's registry key:\n\n  **HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\myservice**\n\n  In case the service was installed using SvcBatch, additional\n  **Parameters** sub key is created under the service's\n  registry key that contains arguments SvcBatch will merge at\n  runtime with the value of **ImagePath**.\n\n  The changes made, will be used next the service starts.\n\n\n* **Starting services**\n\n  To manually start the service use either `svcbatch`, `sc`\n  or Microsoft Services GUI application.\n\n  SvcBatch will append any additional arguments from the\n  service start application to the script file's existing arguments\n  defined at install time.\n\n  Since SvcBatch version **3.0.0**, you can use the\n  SvcBatch itself to start the service.\n\n  ```no-highlight\n  \u003e svcbatch create myservice myservice.bat param1\n\n  ...\n\n  \u003e svcbatch start myservice param2 param3\n\n  ```\n\n\n  When started the `myservice.bat` will receive `param1 param2 param3`\n  as arguments.\n\n\n\n* **Notice**\n\n  If the program started from a service batch file creates\n  its own child processes, ensure you setup the following\n  privileges to the service:\n\n  ```no-highlight\n  \u003e svcbatch configure myservice --privs=SeDebugPrivilege\n\n  ```\n\n  This will allow SvcBatch to terminate the entire\n  descendant process tree on shutdown in case the\n  child process creates a process with different\n  security credentials.\n\n  Also check the [Managing Services](#managing-services)\n  section for further guidelines.\n\n\n## Managing Services\n\nTo get an overview on how to create and manage\nSvcBatch services, check the [managing](docs/manage.md)\nsection for some basic guidelines.\n\n\n## Debugging Services\n\nDebugging a service can be a complex task, because the services\nrun without interacting with the user.\n\nIn case your service fails without apparent reason, first check\nthe Windows Event Log.\n\nThe next option is to use **debug** build of the SvcBatch.\nDownload or build svcbatch.exe compiled with `_DEBUG=1` option\nand replace the svcbatch.exe with this binary.\n\nDebug version of SvcBatch will create a **svcbatch_debug.log** file\ninside the **TEMP** directory of the current service user account.\n\nThe typical content of the **svcbatch_debug.log** file might\nlook something like the following:\n\n\n```no-highlight\n\n```\n\nThe format of this log file is:\n\n**[ProcessId:ThreadId:MonthDayYear/HourMinuteSecond.Millisecond:Mode:FunctionName(line)] message**\n\n\nIf the **svcbatch_debug.log** file already exists, debug messages will\nbe appended to the end of the file.\n\nYou can rename **svcbatch.exe** executable to **myservice.exe**\nand modify service ImagePath registry value. When the service\nstart, SvcBatch will use **myservice_debug.log** as log file.\nThis can be useful when multiple service share the same SvcBatch executable.\n\n\n# Examples\n\nTo get an overview on how the SvcBatch is used with the real\napplication, check the [documentation](docs/index.md)\nsection for some basic deployment guideline.\n\n\n# Main Features\n\nHere are listed some of the main features provided by\nSvcBatch.\n\n## Log Rotation\n\nBy default SvcBatch, on startup, creates a `Logs` directory inside its\nworking directory and creates an SvcBatch.log file that is used both\nfor internal logging and capturing output from `cmd.exe`\n\nIt also renames previous log files if the files are\npresent inside `Logs` directory using the following procedure:\n\n```no-highlight\n\n* If exists move SvcBatch.log to SvcBatch.log.0\n* If exists move SvcBatch.log.8 to SvcBatch.log.9\n\n  This means that SvcBatch.log.9 will be overwritten, so make sure\n  to backup SvcBatch.log.9 before log rotation occurs if needed\n\n* If exists move SvcBatch.log.7 to SvcBatch.log.8\n* ...\n* ...\n* If exists move SvcBatch.log.1 to SvcBatch.log.2\n* If exists move SvcBatch.log.0 to SvcBatch.log.1\n* Create new SvcBatch.log and use it as current log file.\n\n```\n\n\n## Command Line Options\n\nSvcBatch command line options allow users to customize\nservice deployments. Options are case insensitive and\ndefined with **/** or **-** as command switch when running in\nservice mode, or with **--** for SvcBatch service management.\nThis means that `-h or /H` and `--Wait or --wait`\ncan be used interchangeably.\n\nCheck the [managing](docs/manage.md) for more info about\ncommand line options when SvcBatch is used for managing services.\n\nCommand line option value can be either the rest of the\ncommand option or the entire next argument.\n\nIn case the value is the rest of the command option,\nthe command switch must be **/** and the\ncharacter after the option must be **:** character,\nfollowed by the actual option value.\n\nFor example:\n\n```no-highlight\n\u003e svcbatch create myService ... /L:log\\directory ...\n\nIs the same as\n\n\u003e svcbatch create myService ... -l log\\directory ...\n\n```\n\nAfter handling switches SvcBatch will pass remaining\narguments to the script interpreter.\n\nThe first argument is treated as script file.\nIf the first argument is not the absolute path, it will\nbe resolved relative to the service home directory.\n\n\nIf there are no additional arguments, SvcBatch will\nappend `.bat` to the running Service Name.\nIn that case, if `ServiceName` contain any of the\ninvalid file name characters `/\\:;\u003c\u003e?*|\"`,\nthe service will fail and error message will be\nreported to Windows Event log.\n\n\nAlthough command options are case insensitive,\nuse capital letters with **/** command switch,\nand lowercase letters with **-** command switch.\n\n\n\n\n\n* **F [features]**\n\n  **Set runtime features**\n\n  This option sets various runtime features.\n  The **features** parameter is a combination of\n  one or more characters, where each character sets\n  the particular feature option.\n\n  Feature options are case sensitive, and can be\n  listed in any order.\n\n  ```no-highlight\n      \u003cB\u003e\u003cL\u003e\u003cN\u003e\u003cP\u003e\u003cQ\u003e\u003cR\u003e\u003cT\u003e\u003cW\u003e\u003cY\u003e\u003c0|1|2\u003e\n  ```\n\n    * **B**\n\n      **Generate CTRL_BREAK on service stop**\n\n      This option can be used to send `ctrl+break` instead `ctrl+c`\n      signal when the service is stopping.\n\n      This is useful when the service batch file uses `start /B ...`\n      to launch multiple applications.\n\n      ```batchfile\n      ...\n      start /B some.exe instance1\n      start /B some.exe instance2\n      start /B some.exe instance3\n      ...\n\n      ```\n\n      When using `start /B application`, the application does\n      not receive `ctrl+c` signal. The `ctrl+break` is the only\n      way to interrupt the application.\n\n\n    * **L**\n\n      **Use local time**\n\n      This option causes all logging and rotation\n      to use local instead system time.\n\n\n    * **P**\n\n      **Enable preshutdown service notification**\n\n      When defined, SvcBatch will accept `SERVICE_CONTROL_PRESHUTDOWN` control code.\n      The service control manager waits until the service stops or the specified\n      preshutdown time-out value expires\n\n\n    * **Q**\n\n      **Disable logging**\n\n      This option disables both logging and log rotation.\n\n      Use this option when output from script file is not needed or\n      service batch file manages logging on its own.\n\n\n      **Notice**\n\n      Any eventual log rotation option will not be processed.\n\n\n    * **R**\n\n      **Enable log rotation by control code**\n\n      When defined, SvcBatch will accept custom **234**\n      control code and initiate log rotation when this control\n      is signaled.\n\n      Note that **234** is our custom service control code.\n      Number **234** has been randomly chosen, since win32\n      API requires that this number must be larger then `127` and\n      lower then `255`.\n\n      To initiate log rotation manually use the following:\n\n      ```no-highlight\n      \u003e svcbatch control myService 234\n\n      ```\n\n      In case the last log rotation was less then `2` minutes ago,\n      or if there was no data written to the log file from the last\n      rotation, SvcBatch will not rotate the logs.\n\n\n    * **T**\n\n      **Truncate log on rotation**\n\n      If set this option will truncate existing\n      log file on log rotation instead creating\n      a new log file.\n\n\n\n\n\n    * **Y**\n\n      **Write Y to child console**\n\n      If set this option will write `Y\\r\\n` characters to script interpreter's\n      console standard input.\n\n      This option is enabled by default when **cmd.exe** is used,\n      and handles `Terminate batch job (Y/N)?` prompt.\n\n\n    * **0**\n\n      Flags **[0|1|2]** determine how the SvcBatch will handle\n      service failure in case it enters a `STOP` state\n      without explicit Stop command from the SCM.\n\n      This mode will set the error code when the service\n      fails. The error message will be written to\n      the Windows Event log and service will enter a stop state.\n\n      If the service was in `RUNNING` state the error\n      code will be set to `ERROR_PROCESS_ABORTED`, otherwise\n      the error code will be set to `ERROR_SERVICE_START_HANG`.\n\n      You can use this mode to initialize service recovery if\n      defined.\n\n      ```no-highlight\n\n      \u003e sc failure myService reset= INFINITE actions= restart/10000\n\n      \u003e sc failureflag myService 1\n\n      ```\n\n      The upper example will restart `myService` service after `10`\n      seconds if it enters a stop state without Stop command.\n\n      **This is the default mode.**\n\n\n    * **1**\n\n\n      This mode will not set the error code when the service\n      fails. The information message will be written to\n      the Windows Event log and service will enter a stop state.\n\n      The typical usage of this feature is for the services\n      that run for some time and then stop.\n\n\n    * **2**\n\n      This mode will not report error code to the SCM when\n      the service fails. The error message will be written to\n      the Windows Event log.\n      SvcBatch will call `exit(ERROR_INVALID_LEVEL)` and terminate\n      the current service.\n\n\n\n\n* **C [program][\u003c[\u003e parameters \u003c]\u003e]**\n\n  **Use alternative program for running scripts**\n\n  This option allows to use alternative **program** program\n  instead default **cmd.exe** to run the scripts.\n\n  For example:\n\n  ```no-highlight\n  \u003e svcbatch create ... /C:[ powershell -NoProfile -ExecutionPolicy Bypass -File ] myservice.ps1 ...\n\n  ```\n\n  SvcBatch will execute **powershell.exe** instead **cmd.exe** and pass\n  **[ parameters ]** as arguments to the powershell.\n\n  Additional **parameters** for alternative shell must be enclosed\n  inside square brackets before script file and its arguments.\n\n  Parameters for default **cmd.exe** interpreter\n  are **/D /E:ON /V:OFF /C**.\n\n  ```no-highlight\n  \u003e svcbatch create ... /C:cmd.exe [ /D /E:ON /V:OFF /C ] myservice.bat ...\n\n  ```\n\n  If the **program** parameter contains any **@** or **%** characters,\n  SvcBatch will evaluate all environment strings in the **program** parameter\n  and use it as application name.\n\n  In case the **program** parameter is not an absolute path,\n  SvcBatch will search the current environment for the **program[.exe]**\n  application.\n\n\n\n* **K [depth]**\n\n  **Set the nested process kill depth**\n\n  This option sets the **depth** of the process\n  tree that SvcBatch will kill on service stop.\n\n  The valid **depth** range is between **0**\n  and **4**. By default this value is set to zero.\n\n  This option is used only when manually stopping the\n  service. In case the service STOP is initiated by\n  system shutdown, SvcBatch will not traverse its\n  process tree, but rather let the operating system\n  to kill all child processes.\n\n  Use this option if the service script file creates\n  a process that do not respond to STOP command, but\n  keeps running in the background.\n\n\n* **E [name=value]**\n\n  **Sets environment variable**\n\n  This option allows to set the contents of the specified\n  environment variable. The content of the **name** environment\n  variable is to the **value**.\n\n  For example:\n\n  ```no-highlight\n  \u003e svcbatch create ... /E:NOPAUSE=Y /E:CATALINA_BASE=$WORK ...\n\n  ```\n\n  This will set the `NOPAUSE` environment variable to `Y`,\n  and `CATALINA_BASE` to the value of the current working\n  directory.\n\n  SvcBatch will evaluate **value** parameter and replace each\n  **$variable** string with corresponding runtime value.\n\n  If the **$variable** does not exits, it will be replaced by\n  empty string.\n\n  The **$WORK** will be evaluated to the current working directory,\n  **$NAME** will set the **value** to the current Service name, etc.\n\n\n  The runtime **variable** values are:\n\n  ```no-highlight\n\n    APPLICATION Program application path\n    BASENAME    Program application name\n    DISPLAYNAME Service display name\n    HOME        Home directory\n    LOGS        Logs directory\n    NAME        Service Name\n    RELEASE     SvcBatch release version\n    UUUID       Service UUID\n    VERSION     SvcBatch version number\n    WORK        Work directory\n\n  ```\n\n\n\n  The following example will modify `PATH` environment\n  variable for the current process:\n\n  ```no-highlight\n  \u003e svcbatch create ... -e \"PATH=$ProgramFiles\\SomeApplication;$PATH\" ...\n\n  ```\n\n  In the upper example, each **$variable** will be evaluated\n  to the current runtime value.\n\n  Each **$$** character pair will be replaced by the\n  single **$** character. This allows to use **$** characters\n  as part of **value** without evaluating them.\n\n\n  ```no-highlight\n  \u003e svcbatch create ... /E \"SOME_VARIABLE=RUN$$1\" ...\n\n  ```\n  In the upper example, SvcBatch will set `SOME_VARIABLE`\n  environment variable to the value `RUN$1`.\n\n\n\n  SvcBatch will evaluate **E** command options in order they\n  are defined in service configuration.\n\n  SvcBatch will first set all\n  [Private Environment Variables](#private-environment-variables)\n\n  After that it will evaluate and set all **/E:name=value** variables.\n\n\n\n* **EE [variables]**\n\n  **Export private environment variables**\n\n  This option exports various runtime environment variables.\n  The **variables** parameter is a combination of\n  one or more characters, where each character sets\n  the particular environment variable.\n\n  Variables are case sensitive, and can be\n  listed in any order.\n\n  ```no-highlight\n\n    A   Program application\n    B   Program application name\n    D   Service display name\n    H   Home directory\n    L   Logs directory\n    N   Service Name\n    R   SvcBatch release version\n    U   Service UUID\n    V   SvcBatch version number\n    W   Work directory\n\n  ```\n\n  Each variable name will be evaluated at runtime\n  using either default or prefix or the one defined\n  by the **/EP:PREFIX** command option.\n\n  ```no-highlight\n\n    A  ...  [PREFIX]_APPLICATION\n    B  ...  [PREFIX]_BASENAME\n    D  ...  [PREFIX]_DISPLAYNAME\n    H  ...  [PREFIX]_HOME\n    L  ...  [PREFIX]_LOGS\n    N  ...  [PREFIX]_NAME\n    R  ...  [PREFIX]_RELEASE\n    U  ...  [PREFIX]_UUID\n    V  ...  [PREFIX]_VERSION\n    W  ...  [PREFIX]_WORK\n\n  ```\n\n  The following example will export `SVCBATCH_PROCESSID`\n  and `SVCBATCH_VERSION` environment variables with the\n  values set to their corresponding runtime values.\n\n  ```no-highlight\n  \u003e svcbatch create ... /EE:PV ...\n\n  ```\n\n  This feature is usually used to export specific runtime variable(s).\n\n  The following example will only export service's home\n  and work directories as `MYSERVICE_HOME` and `MYSERVICE_WORK`\n  environment variables:\n\n  ```no-highlight\n  \u003e svcbatch create myService ... /EP:@ /EE:HW ...\n\n  ```\n\n\n\n* **EP [prefix]**\n\n  **Sets private environment variables prefix**\n\n  By default SvcBatch uses uppercase program name as prefix\n  for private environment variables names.\n\n  Check [Private Environment Variables](#private-environment-variables)\n  section, for the list of exported variables.\n\n  To change default **SVCBATCH** prefix, add\n  **/EP:prefix** to your service configuration.\n\n\n  The following example will cause SvcBatch to\n  export **ASERVICE_NAME** instead default **SVCBATCH_NAME**, etc.\n\n  ```no-highlight\n  \u003e svcbatch create ... /EP:ASERVICE ...\n\n  ```\n\n  In case the **prefix** is a single **@** character,\n  SvcBatch will use service name as private environment prefix.\n\n  The following example will cause SvcBatch to\n  export **MYSERVICE_NAME** instead default **SVCBATCH_NAME**, etc.\n\n  ```no-highlight\n  \u003e svcbatch create myService ... /EP:@ ...\n\n  ```\n\n\n\n\n* **H [path]**\n\n  **Set service home directory**\n\n  This option enables users to explicitly set the\n  home directory.\n\n  The home directory is the location from where all relative\n  path parameters will be resolved.\n\n  If not specified, the home directory will set to the\n  path of the batch file if it was defined\n  as an absolute path. Otherwise the directory of the svcbatch.exe\n  will be used as home directory.\n\n  In case the **path** is relative, it will be resolved\n  either to the directory of the batch file, if it was\n  defined as an absolute path, or to the directory of the\n  svcbatch executable.\n\n  The resulting **path** value must exist on the system\n  or the service will fail to start, and write an error message\n  to the Windows Event log.\n\n\n* **L [path]**\n\n  **Set service log directory**\n\n  This option allows a user to set the log directory, which is where\n  SvcBatch will create any runtime log files.\n\n  If set, the **path** parameter will be used as the\n  location where SvcBatch.log files will be created.\n  SvcBatch will create a **path** directory if it doesn't exist.\n\n  If not set, SvcBatch will create and use the  **SVCBATCH_WORK\\Logs**\n  directory as a location for log files that has to be created.\n\n  If the **path** is not the absolute path, it will\n  be resolved relative to the **W** directory.\n\n  **Notice**\n\n  This directory has to be unique for each service instance. Otherwise the\n  service will fail if another service already opened SvacBatch.log\n  in that location.\n\n\n\n* **LN [name]**\n\n  **Set log file name**\n\n  This option allows a user to set the alternate log file names.\n\n  By default SvcBatch will use `SvcBatch.log` as **name**.\n  To redefine default log name use the **LN**\n  command option at service install:\n\n  ```no-highlight\n  \u003e svcbatch create ... /LN:myService.log ...\n\n  ```\n\n  If the **name** parameter contains `@` characters,\n  it will be treated as a format string\n  to our custom `strftime` function.\n\n  When using `strftime` filename formatting, be sure the\n  log file name format has enough granularity to produce a different\n  file name each time the logs are rotated. Otherwise rotation\n  will overwrite the same file instead of starting a new one.\n  For example, if logfile was `service.@Y-@m-@d.log` with log rotation\n  at `5` megabytes, but `5` megabytes was reached twice in the same day,\n  the same log file name would be produced and log rotation would\n  overwrite the same file.\n\n  **Supported formatting codes**\n\n  Here are listed the supported formatting codes:\n\n  ```no-highlight\n    @d  Day of month as a decimal number (01 - 31)\n    @F  Equivalent to @Y-@m-@d\n    @H  Hour in 24-hour format (00 - 23)\n    @j  Day of the year as a decimal number (001 - 366)\n    @m  Month as a decimal number (01 - 12)\n    @M  Minute as a decimal number (00 - 59)\n    @S  Second as a decimal number (00 - 59)\n    @s  Millisecond as a decimal number (000 - 999)\n    @w  Weekday as a decimal number (0 - 6; Sunday is 0)\n    @y  Year without century, as decimal number (00 - 99)\n    @Y  Year with century, as decimal number\n    @0  Current counter as a decimal number (0    -    9)\n    @2  Current counter as a decimal number (00   -   99)\n    @4  Current counter as a decimal number (0000 - 9999)\n\n  ```\n\n  Make sure that log names contain only valid file name characters.\n  The following are reserved characters:\n\n  ```no-highlight\n    \u003c  (less than)\n    \u003e  (greater than)\n    :  (colon)\n    ;  (semicolon)\n    \"  (double quote)\n    /  (forward slash)\n    \\  (backslash)\n    |  (vertical bar or pipe)\n    ?  (question mark)\n    *  (asterisk)\n  ```\n\n  In case the result from `strftime` contains any of the reserved\n  characters the function will fail.\n\n\n* **LM [number]**\n\n  **Set maximum number of log files**\n\n  In case the **number** contains a single decimal number\n  between `1 and 9` it will be used instead default `1 .. 2`.\n\n  ```no-highlight\n  \u003e svcbatch create ... /LM:4\n\n  ```\n\n  Instead rotating Svcbatch.log from `1 .. 2` it will rotate\n  exiting log files from `1 .. 4.`.\n\n\n\n* **LR [rule]**\n\n  **Rotate logs by size or time interval**\n\n  Depending on the **rule** parameter service can rotate\n  log files at desired interval, once a day at specific time\n  or when log file gets larger then defined size.\n\n  Time and size values can be combined, which allows\n  to rotate logs at specific time or size which ever first.\n  For example one can define **rule** so that rotate logs\n  is run each day at `17:00:00` hours or if log files gets\n  larger then `100K` bytes.\n\n  To combine multiple values use the **+** character as\n  value separator. The order is important.\n\n  ```no-highlight\n    \u003c@Time\u003e\u003c+\u003e\u003cSize\u003e\n  ```\n\n  ```no-highlight\n  \u003e svcbatch create ... /LR:@17:00:00+100K\n\n  ```\n\n  If time is given without a colons, SvcBatch will use it\n  as minutes between log rotation.\n\n  ```no-highlight\n  \u003esvcbatch create ... /LR:@90+200K\n\n  ```\n\n  The upper example will rotate logs each `90` minutes. In case\n  log file gets larger the 200Kbytes within that interval,\n  it will be rotated as well. In that case internal timer\n  will be reset and next rotation will occur after `90` minutes.\n\n  In case **rule** parameter is `@0` SvcBatch will rotate\n  log files each day at midnight. This is the same as\n  defining `/LR:@00:00:00`.\n\n  In case **rule** parameter is `@60` SvcBatch will rotate\n  log files every full hour.\n\n  In case **rule** parameter for rotation based on log file size\n  is less then `1K` (1024 bytes), SvcBatch will not rotate logs by size.\n\n  The **rule** parameter uses the following format:\n\n  ```no-highlight\n      \u003c[@hh:mm:ss|@minutes]\u003e\u003c+\u003e\u003csize[B|K|M|G]\u003e\n  ```\n\n\n\n* **S [script][\u003c[\u003e arguments \u003c]\u003e]**\n\n  **Execute script file on service stop or shutdown**\n\n  If defined, on shutdown or stop event the service\n  will create separate `svcbatch.exe` process and call **script**.\n  The purpose of that file is to use some sort of `IPC` mechanism\n  and signal the service to exit.\n\n  This is particularly useful for services that do not handle\n  `CTRL_C_EVENT` or have specific shutdown requirements.\n\n  In case the **script** equals to **NUL**, SvcBatch\n  will only pass additional arguments to the script interpreter.\n  Service will fail to start if the additional argument(s) were not defined.\n\n  In case the **script** starts with **./** or **.\\\\**,\n  SvcBatch will use the string following the **./** or **.\\\\**\n  as script file without checking for its existence.\n\n  In case the **script** equals to **@**,\n  SvcBatch will use the main service script file for shutdown,\n  add pass **stop** string as the argument to that script file,\n  if the additional argument(s) were not defined.\n\n\n  To set additional **arguments** for stop script\n  enclose them inside square brackets `[ ... ]`.\n\n\n  ```no-highlight\n\n  \u003e svcbatch create ... /S:stop.bat /S:[ --connect --command=:shutdown ] ...\n  ...\n  \u003e svcbatch create ... /S:@ ...\n  ...\n  \u003e svcbatch create ... /S:@ [ used instead default stop ] ...\n\n  ```\n\n\n* **SM [number]**\n\n  **Set maximum number of stop log files**\n\n\n  Default maximum number of stop log files is `0` (zero),\n  which means that no log rotation will be performed for stop\n  script logging. To enable log rotation for stop logging, set\n  the **number** parameter value between `1 and 9`.\n\n  ```no-highlight\n  \u003e svcbatch create ... /SM:2 /SN:myService.stop.log\n\n  ```\n\n  This will rotate stop log files from `1 .. 2`.\n\n  **Notice**\n\n  If this option is defined, and **SN** option was not defined,\n  SvcBatch will use default `SvcBatch.stop.log` as stop log name.\n\n\n* **SN [name]**\n\n  **Set stop log file name**\n\n  This option allows a user to enable stop logging for scripts\n  defined by **S** option.\n\n  ```no-highlight\n  \u003e svcbatch create ... /SN:myService.stop.log ...\n\n  ```\n\n  The **name** parameter is handled the same as\n  described with **LN** command option.\n\n\n\n* **ST [timeout]**\n\n  **Set stop timeout in seconds**\n\n  This option sets the **timeout** when service receives\n  stop or shutdown signal.\n  The valid **timeout** range is between `2` and `120`\n  seconds (two minutes).\n\n  By default this value is set to `10` seconds.\n\n  Also make sure to check the **WaitToKillServiceTimeout**\n  value specified in the following registry key:\n\n  **HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control**\n\n  If the operating system is rebooting, this value is used\n  as time limit.\n\n\n* **T [path]**\n\n  **Set temp directory**\n\n  This option allows a user to set different temp directory\n  then the one defined by the service account environment.\n\n  If the **path** is not the absolute path, it will\n  be resolved relative to the **W** directory.\n\n  SvcBatch will set **TEMP** and **TMP** environment\n  variables to that directory.\n\n  In case the directory specified by **path** parameter\n  does not exists, it will be created.\n\n\n* **W [path]**\n\n  **Set service working directory**\n\n  This option enables users to explicitly set the working\n  directory. When batch file is executed its current directory\n  is set to this path.\n\n  If not specified, the working directory is set\n  to the home directory defined using **H** option.\n  Check **H** command option for more details.\n\n  If the **path** is not the absolute path, it will\n  be resolved relative to the **H** directory.\n\n\n  **Notice**\n\n  If defined, the working directory must exist and have\n  read and write access rights for the current process.\n\n\n\n\n## Private Environment Variables\n\nSvcBatch sets a few private environment variables that\nprovide more info about running environments to batch files.\nThose variable by default have **SVCBATCH** prefix,\ndetermined from the program executable name.\n\nHere is the list of environment variables that\nSvcBatch sets for each instance:\n\n\n* **SVCBATCH_HOME**\n\n  This variable is set to the service home directory.\n\n\n* **SVCBATCH_LOGS**\n\n  This variable is set to the service's output directory.\n\n  In case the logging is disabled, by using **/F:Q**\n  command option, this variable is set to the **SVCBATCH_WORK**\n  directory.\n\n\n* **SVCBATCH_NAME**\n\n  This variable is set to the actual service name\n  defined with `svcbatch create [service name] ...`\n\n  ```batchfile\n  @echo off\n  rem\n  rem Simple example\n  rem\n\n  echo Running service %SVCBATCH_NAME%\n\n  ```\n\n* **SVCBATCH_UUID**\n\n  This is the service's unique identifier in following hexadecimal format\n  `abcd-01234567-89ab-cdef-0123-456789abcdef`.\n  The first four digits are current process id, and remaining digits\n  are randomly generated at service startup.\n\n  The **SVCBATCH_UUID** environment variable can be used\n  inside batch file when unique identifier is needed.\n\n  ```batchfile\n  rem\n  rem Create unique temp directory\n  rem\n  md \"%TEMP%\\%SVCBATCH_UUID%\"\n  ...\n  ... do some work using that directory\n  ...\n  rd /S /Q \"%TEMP%\\%SVCBATCH_UUID%\"\n\n  ```\n\n* **SVCBATCH_WORK**\n\n  This variable is set to the service working directory.\n\n  The working directory is set to **SVCBATCH_HOME**\n  directory, unless the **W** command option was configured.\n\n  This variable is set as current directory for the\n  shell process launched from SvcBatch, and as base directory\n  for **SVCBATCH_LOGS** in case the **L** parameter\n  was defined as relative path.\n\n\n**Notice**\n\n  In case you rename SvcBatch executable from **svcbatch.exe**\n  to for example **myservice.exe**, SvcBatch will use **MYSERVICE**\n  as prefix for those variables. In that case it will export\n  **MYSERVICE_NAME**, **MYSERVICE_HOME**, etc.\n\n  In case the **/EP:@** or **/EP:PREFIX** command option is\n  defined, it will take precedence over this feature.\n\n**Important**\n\n  Make sure to use only ASCII alphanumeric and underscore (`_`)\n  characters as executable name, or the service will fail to start.\n\n\n\n## Stop and Shutdown\n\nWhen you type `sc.exe stop myservice` or when your machine gets into the\nshutdown state, SvcBatch running as a service will receive\nstop or shutdown event. SvcBatch will send `CTRL_C_EVENT` to its\nchild processes or run shutdown batch file in case\n**/S [batchfile]** was defined at install time.\n\nIt is up to the application started from batch file to\nhandle this event and do any cleanup needed and then exit.\nBy default, on startup, SvcBatch writes 'Y' to `cmd.exe` stdin,\nto handle that obnoxious `Terminate batch job (Y/N)?` prompt.\nIf batch file or any of downstream processes do not exit within stop timeout,\nSvcBatch will give another 20 seconds for all processes to exit.\nAfter that timeout it will simply kill each descendant process\nthat originated from svcbatch.exe.\n\n\n\n## Version Information\n\nThe simplest way to obtain the version information\nis to right click on the `svcbatch.exe` from Windows File\nExplorer, click on Properties, and then on the Details tab.\n\n\nAnother way to get SvcBatch version and build information\nis to open command prompt and type\n\n  ```no-highlight\n  \u003e svcbatch.exe version\n  SvcBatch 1.2.3.4 ...\n\n  \u003e\n  ```\n\nMake sure to use the correct information when filing\nbug reports.\n\n\n\n## Error Logging\n\nSvcBatch logs any runtime error to Windows Event Log.\nUse Windows **Event Viewer** and check `Windows Logs/Application/YourServiceName`\nevents.\n\n\n\n# Limitations\n\nSvcBatch have limits for the following features:\n\n\n* **Service Name**\n\n  The Service Name must consists of only ASCII characters\n  except the following set:\n\n  ```no-highlight\n    \u003c  (less than)\n    \u003e  (greater than)\n    :  (colon)\n    ;  (semicolon)\n    \"  (double quote)\n    /  (forward slash)\n    \\  (backslash)\n    |  (vertical bar or pipe)\n    ?  (question mark)\n    *  (asterisk)\n  ```\n\n  Service Name must start with alphanumeric character,\n  and its length is limited to **255** characters.\n\n  Service will **fail** to start if the upper criteria is not met.\n\n\n* **Program File Name**\n\n  Default Program File Name is **svcbatch.exe**.\n\n  Program File Name can contain only alphanumeric ASCII\n  characters including underscore (`_`) character,\n  and must end with **.exe** file extension.\n\n\n* **File name length**\n\n  The maximum file name length must be less then\n  **2040** characters, and is defined by the\n  `#define SVCBATCH_PATH_SIZ 2040` macro\n  inside [svcbatch header file](svcbatch.h)\n\n\n\n* **Maximum number of arguments**\n\n  The maximum number of arguments that can be passed\n  to the command processor is limited to **32**,\n  and is defined by the `#define SVCBATCH_MAX_ARGS 32`\n  macro inside [svcbatch header file](svcbatch.h)\n\n  This option also defines the maximum number of\n  parameters passed to the command interpreter when\n  **C** command option is used.\n\n\n\n\n# License\n\nThe code in this repository is licensed under the [Apache-2.0 License](LICENSE.txt).\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmturk%2Fsvcbatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmturk%2Fsvcbatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmturk%2Fsvcbatch/lists"}