Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


March 2000

More About Srvany


RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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.

End of Article



Reader Comments
Setup of srvany Registry Keys as discussed under the "Keys to Success" will not work as Mark has listed. To make the application Notify run properly as a service, a new subkey Parameters must be created that contains the Application and AppParameters value entries. The registry locations should be as follows:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Notify\Parameters\Application: REG_SZ: D:\apps\notify\notify.exe
and
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Notify\Parameters\AppDirectory: REG_SZ: E:\files.
Note: Got this info from the Srvany instructions of the Resource Kit CD.
thanks


Gene K. Burton June 30, 2000


while installing a service thro srvany.exe,i can c both the files(srvany.exe and my application exe) is running in the system??.. why??

Anandhi August 01, 2001


Both srvany and your app have to be running. Your app for obvious reasons and srvany because it is doing the work of the service (stopping/starting, etc).

whatever October 31, 2001


Thanks Gene for your comment...it now works as it should!

Bill April 07, 2002


Where can I get the Microsoft Windows NT Server 4.0 Resource Kit and how much does it cost?

Bryan Duncan October 09, 2002


How can I write a C++ program that will run as a Service, without using Microsoft's compiler or Srvany? I am familiar with writing Windows application programs using the Watcom C++ Version 11 compiler, but don't know how to modify my programs to run as Services.

Marshall Solomon December 24, 2002


One very important element that you left out: Before creating the string 'Application', you must create a sub-key called 'Parameters'. Read here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;137890

Of course, this is for Win2K.



Jason March 11, 2004


We have srvany running a program on 2000 Server. My question is, can it be used on Windows 2000 Professional or Windows XP Professional.

Gary Hart March 17, 2004


This can indeed by used on Windows 2000 Professional as I have just tested it and it works like a charm. Now all I have to do is try to unistall the service in a similar fashion :)

Gavo April 21, 2004


Great reading, Mark. I am having a problem with my application running with srvany. When I boot the computer the application is not being run (or even located). There are no errors returned that I can find. The only problem that I can see may be one of the parameters that was enetered at installation. Namely, the AppParamerers and AppEnvironment sub keys. The appParameters string that I used was the path and filename to the exe that I want to run as a service. I did not do a AppEnvironment key. Are these correct? I hainstalled them as needed in the Parameters subkey that I made.

Thanks


Ryan April 23, 2004


 See More Comments  1   2   3   4 

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. ...

Getting your iPhone to Sync with Exchange 2003

Follow these steps to use an iPhone with Exchange. ...


Related Articles Srvany

Windows OSs Whitepapers Protecting Microsoft SharePoint

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement