When you install your application as a Service Process, the application will run in the background and will be invisible in the "Application" folder on the Windows Task Manager. An application that runs as a Service Process does not stop if the user logs off, it just keeps running. A sample of an application that runs as a service process is Symantec's WinFax. The program sill receives faxes, even if the user is not logged in!
There are 2 main advantages of running your application as a Service Process: Invisible in the Application folder in the Task manager and running, even when the user is not logged in.
Now, how can we make our FiveWin application be a Service Process? Well, the windows API function "RegisterServiceProcess" is the solution. This function registers or unregisters an application as a service process. The RegisterServiceProcess API function accepts two parameters. the first parameter is the process ID of the application. To retrieve the process ID of an application, we use a second Windows API function: GetCurrentProcessId. This Windows API call does not need a parameter.
The second parameter of RegisterServiceProcess specifies whether the service is to be registered or unregistered. A value of 1 registers the application as a service process, 0 unregisters the application as a service process.
Sample FiveWin Code:
Function Main()
ServiceProcess(1)
/*
Your code here...
*/
Return NIL
Function ServiceProcess( mode )
Local nProcessId := 0
Default mode := 0
nProcessId := GCP( )
If Abs( nProcessId ) > 0
RSProcess( nProcessId, mode )
Endif
RETURN
DLL32 FUNCTION RSProcess(npID AS LONG ,;
nMode AS LONG ) AS LONG ;
FROM "RegisterServiceProcess" LIB "kernel32.DLL"
DLL32 FUNCTION GCP() AS LONG;
FROM "GetCurrentProcessId" LIB "kernel32.dll"