Recently in Applications Development Category

Not that many of us will need this, but I just went through it & wanted to document the steps.

Objective: Make a console application run as an NT Service on a W2k box. Reason: I want the app to be reachable & "alive" whether I'm logged in or not.

Steps involved are as follows:


  1. Two MS programs are needed: INSTSRV.EXE and SRVANY.EXE. These are included with some of the older Resource Kits but are also, I believe, available on the net. INSTSRV.EXE is the actual service installer while SRVANY.EXE is a "wrapper" that actually is installed as the service and which is what executes your application.
  2. Install both programs in either the \System32 directory or the directory where your app resides. In my case: c:\Mercury.
  3. Be sure the login you're using has administrator privs and that your app is NOT running.
  4. Open a Command Prompt window (aka a "DOS Window" for those over .. whatever). If you've copied the two programs above into your app directory, navigate to that directory. If the two files are in \System32, any prompt will do.
  5. At the prompt, install SRVANY.EXE as a service using INSTSRV.EXE by entering the following:
    C:\>instsrv YourAppName "PathToYourApp\srvany.exe"
    In my case, the command line entry is:
    instsrv Mercury "c:\mercury\srvany.exe"
  6. You should now see a response along the lines of "CreateService SUCCESS".
  7. Verify that your service got added by bringing up your Services applet. In W2k server, it's Control Panel->Administrative Tools->Services.
  8. Configure the service to start however you wish (Automatic or Manual). Set it to log on as a System Account.
  9. We're almost done but not quite. If srvany.exe were started as a service, it wouldn't know what to execute. Notice that we haven't said anything about the name of the actual application (c:\mercury\mercury.exe) anywhere above.
  10. Run regedt32.exe (located in the \system32 directory) and navigate to HKEY_LOCAL_MACHINE -> SYSTEM -> CurrentControlSet -> Services and double-click on the "YourAppName" service entered in step 5 above.
  11. Click on the Edit pulldown and select 'Add key' and create a 'Parameters' key.
  12. Open the 'Parameters' key and add a string value called "Application" (REG_SZ).
  13. Edit "Application" and enter the path to your application (for me, c:\mercury\mercury.exe).
  14. Exit regedt32.exe and, in Services (step 7 above), start your application.

FWIW, another way to start/stop the application: Use the MS Net.exe utility from the command line, as in NET START YourAppName and NET STOP YourAppName. This approach is helpful if you use telnet to access your machine remotely.

~ja

About this Archive

This page is a archive of recent entries in the Applications Development category.

Anti-Virus is the previous category.

Browser is the next category.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.23-en