Subscribe to Windows IT Pro
February 09, 2000 12:04 PM

More About Srvany

Windows IT Pro
InstantDoc ID #8148
Rating: (11)
Run any program as a service

In my last column, I introduced the Microsoft Windows NT Server 4.0 Resource Kit's Srvany tool, which lets you run a program as an NT service, and I explained how to set up the utility. In this column, I explain how to use the tool.

Services such as DNS, DHCP, WINS, and Microsoft Internet Information Server (IIS) run regardless of whether someone is logged on because developers built the programs to do so. But modifying an application to run as a service is difficult if you can't access the application's source code. Srvany lets you run an application as a service whether or not you're logged on or have access to the application's source code. Srvany acts as a kind of envelope for almost any program (i.e., programs that don't require user input) to run in.

Keys to Success
As I explained in my last column, installing Srvany as a service is the first step to set up a program to run as a service. In the installation process, you must create a Registry key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services. I used a fictitious application named notify.exe in my example, and I created a Registry key named HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Notify.

After you create a Registry key for the program you want to run, you need to tell the system to run the program. Open a Registry editor, and go to the Registry key you created. Within the key, create a value entry named Application as a REG_SZ string and enter the application's fully qualified pathname. For example, I'd enter D:\apps\notify\notify.exe for the Application value in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Notify.

Some programs work only if you set the default directory to an arbitrary location. Thus, you need to know how to tell NT to point to such a location. In addition, some programs need NT to pass parameters to them. You need to know how to set up the Registry parameters. To solve both of these problems, you must create two additional Registry keys.

If you want Srvany to run an application in a particular default directory, create a value entry named AppDirectory as a REG_SZ string in Srvany's Registry key and put the directory name in that value entry. To specify a set of parameters to feed to the application, create a value entry called AppParameters as a REG_SZ string in Srvany's Registry key and put the parameters in that value entry. Most of these operations are case insensitive. However, if the program (e.g., notify.exe) requires parameters to be in a particular case, you must use the correct case when you enter those parameters in the AppParameters value entry. So, if notify.exe needed to work by default in the directory E:\files and required a parameter string such as -e -i -Aupdate, you'd have three value entries in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Notify: Application, which would contain the string D:\apps\notify\notify.exe; AppDirectory, which would contain E:\files; and AppParameters, which would contain -e -i -Aupdate.

Console or Network?
After you create the necessary Registry keys to let an application run as a service, you have an important decision to make. You must decide whether you want the service to interact with the console (i.e., use the local keyboard, screen, and mouse) or access network resources; NT won't easily let a service do both.

Start the Control Panel Services applet, find the newly installed service, click the service, and select Startup. The dialog box that opens lets you configure the service to start automatically, manually, or not at all (i.e., to disable the service). At the bottom of the dialog box, you must specify an account to associate the service with.

To make a service interactive, select the Allow Service to Interact with Desktop check box to let the service use the LocalSystem account. The program won't be able to access network resources. To let a service use network resources, associate the service with an account that has network privileges. The LocalSystem account is powerful, but only on the account's machine. In general, the LocalSystem account has no permissions on other machines.

Run with It
After you make the necessary Registry edits and Control Panel adjustments, your program is ready to run as a service. Remember that you can't make every application into a service, so you need to experiment to determine whether Srvany can make your favorite program run as a service.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Jun 29, 2005

    Can you configure srvany to send a WM_CLOSE window to the child process. I think it send a WM_TERMINATE

  • Anonymous User
    7 years ago
    Jun 29, 2005

    Regarding security for the srvany user:
    You can use any user, as long as it has authority to the directories you need to use, and the user right "Log on as a service" has been granted to the account.

    --Joe Netwacker

  • Anonymous User
    7 years ago
    May 19, 2005

    I want to start more than one command with srvany.
    e.g.
    c:
    cd \\programs\\...
    application.exe

    but there is only one row in registriy (Parameters)!

    What can I do?

  • Anonymous User
    7 years ago
    Feb 25, 2005

    ChangeServiceConfig() http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/changeserviceconfig.asp

    can alter the configuration of a service including the log on account.

    If ur using a script such as VB you could use rundll32 to access that function.

  • Anonymous User
    7 years ago
    Feb 25, 2005

    I wrote a Script and installed it on all Hosts. The Problem is, that it needs Admin Rights to work well.
    Is there a chance to change the Log On Account of a Service with a scipt ?
    Hope someone can help.
    Thanks Bernie

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.