Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
how to Check if a Windows feature exists - Hide your app in the Task List Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-May-03
Category
System
Language
Delphi 2.x
Views
217
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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...

Answer:

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. 
1   
2   function RegisterAsService(Active: boolean): boolean;
3   const
4     RSP_SIMPLE_SERVICE = 1;
5     RSP_UNREGISTER_SERVICE = 0;
6   type
7     TRegisterServiceProcessFunction =
8       function(dwProcessID, dwType: Integer): Integer; stdcall;
9   var
10    module: HMODULE;
11    RegServProc: TRegisterServiceProcessFunction;
12  begin
13    Result := False;
14    module := LoadLibrary('KERNEL32.DLL');
15    if module <> 0 then
16    try
17      RegServProc := GetProcAddress(module, 'RegisterServiceProcess');
18      if Assigned(RegServProc) then
19        if Active then
20          Result := RegServProc(0, RSP_SIMPLE_SERVICE) = 1
21        else
22          Result := RegServProc(0, RSP_UNREGISTER_SERVICE) = 1;
23    finally
24      FreeLibrary(module);
25    end;
26  end;


Notice that registering our application as a service has the side-effect of hiding 
our application in the Task List (in Windows Task Manager). 

Sample calls: 

27  procedure TForm1.FormCreate(Sender: TObject);
28  begin
29    RegisterAsService(true);
30  end;
31  
32  procedure TForm1.FormDestroy(Sender: TObject);
33  begin
34    RegisterAsService(false);
35  end;


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 
NT/2000 service... 

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:edspirito@latiumsoftware.com
Visit: http://www.latiumsoftware.com/delphi-newsletter.phphttp://www.latiumsoftware.com/delphi-newsletter.php

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC