Skip navigation

Srvany

Of all the capabilities that separate Windows NT from earlier Microsoft OSs, services are among my favorite. For example, if you run Web or mail server software as a service, you don't need to start up the Web or mail server software every time you reboot the system. Because the software runs as a service, it starts automatically. In addition, services run in the background without cluttering up your desktop or system tray, and they run when no one is logged on. Thus, your Web or mail server software will automatically restart after a power failure. Furthermore, services can run with more rights and permissions than the person operating the computer has.

However, for a program to run as a service, the developer must have built the program to do so. Many programs aren't designed to run automatically. For example, the nifty little Visual Basic (VB) program you whipped up to update content on your Web site every hour won't run unless someone is logged on to make the program work. Rebuilding a program to run as a service isn't difficult, but if you don't have a program's source code, you can't modify the application so that it can run as a service.

The Microsoft Windows NT Server 4.0 Resource Kit's srvany.exe tool offers a solution. Srvany lets you run just about any program as a service, without requiring you to rebuild the application as a service. Installing and using the tool is involved, so I'll use this column and my next column to discuss the process.

The idea behind Srvany is clever: Instead of rebuilding a program as a service, you run the Srvany service, and Srvany launches the program. Because Srvany won't launch all types of programs, you must experiment to determine whether the service will launch a particular program. In addition, some applications will work as services only while you're logged on. When you log off, NT sends a command to all running programs announcing that you're logging off. Many interactive programs, such as word processors and Web browsers, pay attention to the user is logging off command and respond by shutting themselves down. Such programs won't run successfully as services.

Preparing a program to run as a service involves several steps. First, use the resource kit's Instsrv tool to install Srvany as a service. Every service has a Registry key under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services that describes the service. For example, the DHCP Server service's key name is DHCPServer. Srvany lets you choose a key name for its service. This factor is important because you need to install Srvany as a service once for each program that you want to make a service. Installing Srvany under several key names lets you create placeholders for many programs that Srvany can then launch.

Suppose you have a program named notify.exe that you want to make a service. You'd install Srvany and give the service a key name such as notify. To start Instsrv, you'd enter

instsrv notify <fullpathname>\srvany.exe

You need to include the entire path to the location of srvany.exe. I've been able to make Srvany work without specifying a path if I put the srvany.exe file in the \winnt directory, but including the full pathname is a good idea.

You probably also need to change Srvany's service account. When you run a program from the desktop, the program impersonates you and has your permissions and rights. In contrast, a service doesn't run with your permissions and rights. Instead, services run with the permissions and rights of the System account (aka the LocalSystem account). The System account has a lot of power over the workstation or server that the account is running on but virtually no power outside that machine (i.e., over the network). Thus, you might need to let the service that you're running impersonate you. Open the Control Panel Services applet, locate the service, and click Startup. In the Log On As dialog box that opens, select Browse, and select your account and password.

Setting up Srvany is fairly simple. In my next column, I'll use the notify.exe example to explain how to make Srvany run a program as a service.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish