Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  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 log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

More fun TechEd 2005 Resources

Kevin points out some more TechEd resources ...

What service packs and fixes are available?

...


Related Articles Srvany

Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

Are You Satisfied?

A Preliminary Look at Deployment Plans for Microsoft Windows Vista

Related Events 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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Microsoft Exchange & Windows Connections event returns to Las Vegas Nov 10 - 13
Connections returns to Las Vegas for this exciting event where each attendee will receive SQL Server 2008 standard with 1 CAL. Co-located with Microsoft ASP.NET, SQL Server, and SharePoint Connections with over 250 in-depth sessions.

Free Online Event! Virtualization:Get the Facts!
Register now and attend this free, live in-depth online conference on November 13 and 20, 2008, produced by Windows IT Pro. All registrants are eligible to receive a complimentary one-year digital subscription to Windows IT Pro (a $49.95 value)!

Check Out Hyper-V Video on ITTV
Watch Karen Forster's interview on Hyper-V's performance on ITTV.net.

Ease Your Scripting Pains with the Flexibility of PowerShell!
Join MVP Paul Robichaux on December 11, 2008 at 11:00 AM EDT as he equips you with PowerShell basics in 3 introductory lessons, each followed by a live Q&A session—all on your own computer!

Latest Advancements in SSL Technology
There are a variety of different kinds of SSL to explore to ensure customer data is kept confidential and secure. In this paper, we will discuss some of these SSL advances to help you decide which would be best for your organization.

PASS Community Summit 2008 in Seattle on Nov 18-21
The don’t-miss event for Microsoft SQL Server Professionals. Register now and you’ll enjoy top-notch Microsoft and Community speakers and more.



Solving PST Management Problems
In this white paper, read about the top PST issues and how to administer local/network PST Files.

Get Protected -- Data Protection Manager 2007
Protect your virtualized environment with Data Protection Manager

Order Your SQL Fundamentals CD Today!
Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD.

Maximize Your SharePoint Investment: Get Your Data Moving
Watch this web seminar now to learn how to maximize your SharePoint investment! Join us as we take a look at the complex business of securing, accessing and managing vast amounts of information in a global network and various ways to get your data moving.
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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing