Link to home
Start Free TrialLog in
Avatar of mordi
mordiFlag for Israel

asked on

Windows NT 4 service from a VB program

How to make a VB program exe file to run as a Windows NT 4 service?
My program uses odbc connections to work against several SQL Server 7 databases.
If not from VB, can it be done using C++ ?

Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

You can use INSTSRV to set an application to run as an NT service. However if it is running in the local system account it will not normally have access to the network. This can be overcome either by setting the service to run as another account, or there is a registry setting (details are available on technet) to allow the local system account to use named pipes and / or network access. If you use a different account name then the system can have EITHER network access OR a user interface but not both.
Avatar of mordi

ASKER

TimCotte,

How can I use INSTSRV .
Can you explain more in deep what do you mean?

Thanks
INSTSRV is a utility provided with the Windows NT resource kit. There is also a word document accompanying the reskit which details how to go about running an application as a service on NT and also the relevant bits on the network access etc. I can EMail these to you if you post your address or EMail me at TimCottee@Earthling.net and I will send them back.
Avatar of jetforce
jetforce

try this web site

http://vbwire.com/advanced/howto/

it tells you how to create a service on W95/98 and NT

hope this helps
To do this, your must register your program as a service. This is done by passing the process ID of your application to the RegisterService API.

Declarations
Copy the following code into the declarations section of a module:

Public Declare Function GetCurrentProcessId _
Lib "kernel32" () As Long
Public Declare Function GetCurrentProcess _
Lib "kernel32" () As Long
Public Declare Function RegisterServiceProcess _
Lib "kernel32" (ByVal dwProcessID As Long, _
ByVal dwType As Long) As Long
Public Const RSP_SIMPLE_SERVICE = 1
Public Const RSP_UNREGISTER_SERVICE = 0

MakeMeService procedure:

Public Sub MakeMeService()
Dim pid As Long
Dim reserv As Long

pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
End Sub
To restore your application to the Ctrl+Alt+Delete list, call the UnMakeMeService procedure:

Public UnMakeMeService()
Dim pid As Long
Dim reserv As Long

pid = GetCurrentProcessId()
regserv = RegisterServiceProcess(pid, _
RSP_UNREGISTER_SERVICE)
'End Code
Don''t forget to unregister your application as a service before it closes to free up system resources by calling UnMakeMeService.

Avatar of mordi

ASKER

Thank you all, but i can't give you points for this .
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial