birkett/srvany-ng

Run any Windows application as a Service. Drop-in compatible replacement for "srvany.exe" from the W2K3 Resource Kit.

130

stars

55

commits

C

primary language

Dec 11, 2025

updated

README

srvany-ng: Run any Windows application as a Service

A drop in, compatible, replacement for the useful "srvany.exe", found in the Windows Server Resource Kit.
Written in C, for Windows XP and newer.

Support Me

Donate Via Paypal

Differences to the original

  • Open Source
  • 32 and 64 bit binary available
  • Unicode (default) and Multibyte Character Set (MBCS) binaries available
  • No OS/2 application support
  • Service will stop if the launched application exits
  • Added optional configuration to automatically restart the target application on exit
  • Application environment variables will inherit the global environment by default, see Application Environment below
  • Added optional configuration to allow terminating of sub processes spawned by the service

Building

Solution is known to build with Visual Studio 2022, no additional dependencies are needed. The project uses the "v141_xp" toolset to ensure XP / 2003 support, and links to the MSVCRT statically.

Installing

Place srvany-ng in an accessible folder on your system. Install it as a service from an Elevated (Administrator) Command Prompt:

sc create "MyServiceName" start= auto binPath= "C:\Path\To\srvany-ng.exe"
sc description MyServiceName "My services description"

Note the spaces between start=, binPath= and their parameters. This is intended.

Now, open the Registry editor (regedit.exe), and browse to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceName

Create a new Key named "Parameters". In the parameters key, create a new String value named "Application". The value should be the file path to the application you wish to run as a service.

Optional Parameters

Value nameValue typeDescription
AppDirectoryString valueThe starting directory for your application. Usually the same as the folder its executable is in.
AppParametersString valueCommand line arguments to pass to your application on startup.
AppEnvironmentMulti-String valueEnvironment variables to set for your application.
RestartOnExitDWORD valueIf set to 1, and the application exits, srvany-ng will automatically restart it.
OverrideEnvironmentDWORD valueDefault 0, if set to 1 will enable the original srvany environment behaviour described below
TerminateSubProcessesDWORD valueIf set to 1, will use a JobObject to terminate sub processes spawned by the service

Application Environment

The original srvany will overwrite the global environment variables if AppEnvironment is configured. If AppEnvironment is not configured, the default global environment would be passed to the running application.

srvany-ng changes this behaviour, to always pass the global environment variables to the running application, in addition to anything configured in AppEnvironment.

This behaviour can be restored to the original srvany behaviour by setting DWORD OverrideEnvironment = 1 in the registry parameters.

Further Reading

Microsoft support article describing the use of the original srvany.exe: https://support.microsoft.com/en-us/kb/137890

Contributors

birkett

47 commits

forderud

3 commits

shinfd

3 commits

SadPencil

1 commits

birkett/srvany-ng

Run any Windows application as a Service. Drop-in compatible replacement for "srvany.exe" from the W2K3 Resource Kit.

130

stars

55

commits

C

primary language

Dec 11, 2025

updated

README

srvany-ng: Run any Windows application as a Service

A drop in, compatible, replacement for the useful "srvany.exe", found in the Windows Server Resource Kit.
Written in C, for Windows XP and newer.

Support Me

Donate Via Paypal

Differences to the original

  • Open Source
  • 32 and 64 bit binary available
  • Unicode (default) and Multibyte Character Set (MBCS) binaries available
  • No OS/2 application support
  • Service will stop if the launched application exits
  • Added optional configuration to automatically restart the target application on exit
  • Application environment variables will inherit the global environment by default, see Application Environment below
  • Added optional configuration to allow terminating of sub processes spawned by the service

Building

Solution is known to build with Visual Studio 2022, no additional dependencies are needed. The project uses the "v141_xp" toolset to ensure XP / 2003 support, and links to the MSVCRT statically.

Installing

Place srvany-ng in an accessible folder on your system. Install it as a service from an Elevated (Administrator) Command Prompt:

sc create "MyServiceName" start= auto binPath= "C:\Path\To\srvany-ng.exe"
sc description MyServiceName "My services description"

Note the spaces between start=, binPath= and their parameters. This is intended.

Now, open the Registry editor (regedit.exe), and browse to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyServiceName

Create a new Key named "Parameters". In the parameters key, create a new String value named "Application". The value should be the file path to the application you wish to run as a service.

Optional Parameters

Value nameValue typeDescription
AppDirectoryString valueThe starting directory for your application. Usually the same as the folder its executable is in.
AppParametersString valueCommand line arguments to pass to your application on startup.
AppEnvironmentMulti-String valueEnvironment variables to set for your application.
RestartOnExitDWORD valueIf set to 1, and the application exits, srvany-ng will automatically restart it.
OverrideEnvironmentDWORD valueDefault 0, if set to 1 will enable the original srvany environment behaviour described below
TerminateSubProcessesDWORD valueIf set to 1, will use a JobObject to terminate sub processes spawned by the service

Application Environment

The original srvany will overwrite the global environment variables if AppEnvironment is configured. If AppEnvironment is not configured, the default global environment would be passed to the running application.

srvany-ng changes this behaviour, to always pass the global environment variables to the running application, in addition to anything configured in AppEnvironment.

This behaviour can be restored to the original srvany behaviour by setting DWORD OverrideEnvironment = 1 in the registry parameters.

Further Reading

Microsoft support article describing the use of the original srvany.exe: https://support.microsoft.com/en-us/kb/137890

Contributors

birkett

47 commits

forderud

3 commits

shinfd

3 commits

SadPencil

1 commits

Languages

C

59.1%

PowerShell

39.6%

Batchfile

1.3%