Home Index

Run Windows Application as a Windows NT Service Program
 
Date: January 01 2001
Subject: Online Programmer Ezine, Volume 2, No.1
Article: Run Windows Application as a Windows NT Service Program

In previous part of this article we saw how we can run an 
application in background in win98/98. In this article we 
will see how we can run our ordinary applications as a 
service program. Service programs run in background and start
like any other service in windows NT/2000. You can change 
startup type in service start and stop palette. 


Again you must be familiar with windows registry before you 
can use this article. You will need to add your program 
executables names and their path and a few other values in 
windows registry.

Let's assume that our application executable is 'test.exe' 
and its path is 'c:\testapp'. 

1- You will need a file from NT resource kit. Microsoft has 
included this file for this purpose but we chose easiest 
method to do this. First of all you must copy 'srvany.exe' 
file from NT resource kit to application directory.

2- You must add a key in below address with the name you 
have chosen for your service.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services

If we assume TestSrvc will be our service name we must add 
below key:

HKEY_LOCAL_MACHINE
\SYSTEM\CurrentControlSet\Services\TestSrvc


3- Then we must add below values in above key

Name: DisplayName
Type: String (REG_SZ)
Value: TestSrvc

Name: ErrorControl
Type: Number (REG_DWORD)
Value: 0x1 (1)

Name: ImagePath
Type: String (REG_SZ)
Value: c:\testapp

Name: ObjectName
Type: String (REG_SZ)
Value: LocalSystem

Name: Start
Type: Number (REG_DWORD)
Value: 0x2 (2)

Name: Type
Type: Number (REG_DWORD)
Value: 0x110 (272)

4- Then we must make a key inside this key with the name 
'Parameters' :

HKEY_LOCAL_MACHINE
\SYSTEM\CurrentControlSet\Services\TestSrvc\Parameters


5- Inside this key we must store desired application's path 
and exe file name.

Name: Application
Type: String (REG_SZ)
Value: c:\testapp\test.exe

Next time windows NT starts up your application will run 
even before you login to console , right after windows 
startup. If you want to disable service or change service 
type to manual startup you can do this in service start and 
startup palette.

To add these values to specified key you can use install 
maker programs such as "Install Shield" or you can write 
your own install program that adds these values to registry
when installing your application. 

In next issues of this ezine we will see how we can add keys 
and values to windows registry within our program code in 
VB, Delphi and C++ Builder.

If you have any problem or question about this article you
can ask it in our programming forums and I and other 
subscribers will answer your questions. Just visit our 
website and leave your message in our forums !

http://op.htmsoft.com/forums



Home Index
© 2000 OnlineProgrammer (HtmSoft.com). All Rights Reserved