May 27, 2008 - Geeky General    Comments Off on Run an application as a service

Run an application as a service

For security reasons, you try to run every user as a restricted user. At times this can be extremely tough especially when dealing with vendor apps that absolutely have to be run under the administrator account.

Here’s a way to run the app as a service using the “Log on as” service property set to an administrator.

First, back in the Windows 2003 and 2000 resource kits, there are two tools that allow you to run an application as a service. They are called srvany.exe and instsrv.exe. When used together, along with some reg hacks, you can get an app to run at startup as a service. Here is a link that describes that process. That might not be what you need though.

http://www.tacktech.com/display.cfm?ttid=19

Also, you can use two tools from sysinternals.com, filemon and regmon to see what reg keys and exe’s are acccessed when an app is run. When you get all that information, you can go back and assign the local user account full control over those files and registry keys in the access control lists so that when they access them, they will have elevated rights. You can then keep your users as standard restricted users.

instsrv.exe and srvany.exe instructions

Running applications as services can be accomplished using the Windows Server 2003 Resource Kit tools instsrv.exe and srvany.exe. With these two tools, you can create a system service that starts any application you wish. This can allow you to run an application as a service. The Windows 2003 RK tools will also install on Windows XP, so you shouldn’t have any trouble using this procedure on your home system. For those of you with Windows 2000 systems at home, you would need to either copy these tools from the Windows 2000 Resource Kit or as an alternative install the Windows Server 2003 Resource Kit on an alternate Windows 2003 or XP system and then copy instsrv.exe and srvany.exe to the Windows 2000 system. Once you have the Resource Kit or copied these files to your system, you should also ensure that both instsrv.exe and srvany.exe are in a folder that is included in the system path, such as C:\Windows.

You can now create the SAMPLE service. To do this, run instsrv.exe with the following syntax:

instsrv <service name> <path to srvany.exe file>

For example, if you wanted to name the new service SAMPLE and the srvany.exe file was located in the C:\Windows folder, you would run:

instsrv SAMPLE c:\windows\srvany.exe

Now that the service is created, you now need to add a parameter to the service to tell it to run sample.exe once the service starts.

To do this, follow these steps:

  • Run Regedit and navigate to this key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<SAMPLE service name>

In my example, you would navigate to this key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SAMPLE
  • Once you locate the key, right-click on it, select New, and then click Key
  • Name the new key Parameters and hit Enter
  • Next, right-click the Parameters key, select New, and then click String Value. Name the new value Application
  • Now double-click the Application value, enter the path (contained in quotes) to the sample.exe file (such as “C:\Program Files\SAMPLE\sample.exe”), and click OK.

Your service is now ready to run. By default, it will be configured to start automatically once the system boots. To see it run immediately, start the SAMPLE service from the Services MMC.

Instsrv and srvany have almost limitless possibilities. Whenever I need an application to run at system startup, configuring it to run as a service provides an easy way to do so.