Run a regular console application as a service

Some time ago I developed a small tool that allowed you to turn regular old console applications as a service. It’s been download many times but there is no forum to discuss the issues. That’s why I’m creating this blog post now on the suggestion of one of the users. (Thanks Richard)

Below is a link and description of the tool:

http://runasservice.com/

RunAsService is a command line tool that allows you to setup a regular console application to run as a service. Below you will find descriptions and examples of how to do this.
This tool requires that .NET Framework 2.0 be already installed on your computer. If you do not have .NET Framework 2.0 this tool will display a message and not run. You probably already have the .NET Framework 2.0 but if you don’t you can download it here: Microsoft Download Center
IMPORTANT: Any services you install using this tool will
require that this tool remain on that computer in the same location in order for those services to continue functioning. Therefore before installing any services you should make sure this tool is somewhere where it can remain permanently. If you do end up moving this tool use the 'fixservices' action to fix the existing services. 

(details on how to use 'fixservices' can be found below)

RunAsService
    Typing just the name of the tool without specifying any parameters.
    Or specifying incorrect paramters will bring you to the help screen.

RunAsService install [Name] [Display Name] PathToExecutable
    Name
        The name of the service, if none is specified the name 
        will default to the name of the executable.

        You might choose to give it a different name than 
        the executable to keep some kind of existing convention, 
        make it friendlier or make it easier to use commands like 
        'net start' and 'net stop'

    Display Name
        This is how the service name will be displayed in the windows
        services list. If no display name is specified it will default
        to Name, if Name is not specified, it will default to the name
        of the executable.

        Generally the display name is longer and more descriptive
        than the name and gives the user a better idea of what
        the service is and/or does.

    PathToExecutable
        The location of the application you want to run as a service.

        Note, the tool will check if this executable exists, if it
        doesn't find it will not install it.

RunAsService uninstall Name
    Name
        The name of the service you would like to uninstall.

RunAsService fixservices
        Use this action when you've moved the RunAsService executable.
        Services installed using RunAsService require that RunAsService
        remain on the computer and at the same location if
        you move it the services will stop working, use this
        action to fix that.

EXAMPLES

RunAsService install "c:\my apps\Myapp.exe"
        Installs Myapp as a service called "Myapp"

RunAsService install "My Service" "c:\my apps\Myapp.exe"
        Installs Myapp as a service called "My Service"

RunAsService install "My Service" "My Super Cool Service" "c:\my apps\Myapp.exe"
        Installs Myapp as a service internally called "My Service"
        when using commands like 'net start' and 'net stop' and shows
        up as "My Super Cool Service" in Window's services list.

RunAsService uninstall "My Service"
        Uninstalls the service.

RunAsService fixservices
        Use this action if you move this tool. This is because services
        installed using this tool rely on this tool remaining on that 
        computer and at the same location. If you do not call 'fixservices'
        after moving this tool the existing services installed using this
        tool will stop functioning.

NOTES

You can use Windows built in commands to start and stop your
services. For example you can use:
    net start "My Service"
and
    net stop "My Service"

Where "My Service" would be replaced with the name of your service.

CREDITS

This tool was created by Luis Perez on April 2011. For more 
information or to contact me visit RunAsService.com. 

Thank you.

 

Comments

  1. says

    Thank you for this wonderful program!

    I am using it to run a Left 4 Dead 2 dedicated server on a Windows Home Server 2011 machine. I needed to start the server with some command line parameters so on a whim I did a search with RegEdit and found that by adding the parameters to the ImagePath key (Located in HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\”service name”) just like you would with a shortcut I was able to start the server just fine. I toyed around with checking the “Allow service to interact with desktop” box in the Log On tab of the service properties. It would sometimes cause a dialog box to come up which gave me the option to view the program in action in order to execute console commands. But it only comes up when there is activity on the server so I am going to try a remote console interface instead. (Left 4 Dead remote commander looks like an option: http://potentialgamer.com/2008/11/24/left-4-dead-remote-commander/) It’s a private server so I may just be content with using the console from within the game itself.

    On a quick note, I made the mistake of not putting quotes in my net start command around the service name. While that seems to work fine for service names that contain no spaces it does not when there is a space so don’t forget those quotes! ;)

    Thanks again and I will share this with my friends. It’s a very handy tool and as long as someone is comfortable using the command line I see no reason to use any of the commercial options available.

Leave a Reply

Your email address will not be published. Required fields are marked *