Author: Ernesto De Spirito
Some Windows API functions may or may not be present in your Windows version, but
detecting the Windows version is not the best way to know if a function is present
since it may yield a false negative if the user updated a DLL and the update
includes the new function...
To check if an API function exists, we have to load the DLL library where it is
supposed to reside (calling the API LoadLibrary) and then we have to get the
address of the function (calling the API GetProcAddress) which is finally used to
call it. If GetProcAddress returns Nil, then the function isn't present, and if it
returns a value other than Nil, then the function is present, buy we have to take
into account that it isn't necessarily implemented (it may be just a placeholder,
and if we call it, we will get the error code ERROR_CALL_NOT_IMPLEMENTED).
In the following example we implement a function called RegisterAsService which
tries to call the API RegisterServiceProcess to register/unregister our application
as a service. The function returns True if successful.
2 function RegisterAsService(Active: boolean): boolean;
4 RSP_SIMPLE_SERVICE = 1;
5 RSP_UNREGISTER_SERVICE = 0;
7 TRegisterServiceProcessFunction =
8 function(dwProcessID, dwType: Integer): Integer; stdcall;
10 module: HMODULE;
11 RegServProc: TRegisterServiceProcessFunction;
13 Result := False;
14 module := LoadLibrary('KERNEL32.DLL');
15 if module <> 0 then
17 RegServProc := GetProcAddress(module, 'RegisterServiceProcess');
18 if Assigned(RegServProc) then
19 if Active then
20 Result := RegServProc(0, RSP_SIMPLE_SERVICE) = 1
22 Result := RegServProc(0, RSP_UNREGISTER_SERVICE) = 1;
Notice that registering our application as a service has the side-effect of hiding
our application in the Task List (in Windows Task Manager).
27 procedure TForm1.FormCreate(Sender: TObject);
32 procedure TForm1.FormDestroy(Sender: TObject);
I guess this works only for win 9X-Me is there any way a similar move may be made
under win NT/2000?
I believe for Windows NT/2000, the application must be designed to be a Windows
Perhaps you can try running your EXE with SRVANY.EXE, which runs any application as
a service. Of course apps run this way won't be able to take advantage of the
special operating system features available to services, but for the sake of hiding
your app in the Task List, maybe it's enough, I don't know...
Copyright (c) 2001 Ernesto De Spiritomailto:email@example.com