Mega Code Archive

 
Categories / Delphi / Examples
 

Hide your application in windows task manager

There are various ways to attempt hiding an application in the task manager. A simple trick is to set the application title to be empty thus have Windows display an empty entry there (the entry is still in the task manager's list of applications but empty). Another attempt is to register the process while running as a service. The general purpose of running as a service is to allow your program to run without needing to have a user logged on. Common usages are most virus scanners, firewalls or some FTP servers. Services can also have a user interface; they don't need to be 'invisible'. In consumer versions of Windows (95,98,ME) the kernel exports a function RegisterServiceProcess which easily registers an regular application into an service and back. All you need is the process ID. Delphi doesn't import this function - probably because it is not supported in newer Windows versions. To be able to run on Windows NT, 2000 or XP, you should check at runtime the version of Windows and then dynamically load that DLL (with LoadLibrary()) and import the function RegisterServiceProcess. The code below shows a static link to KERNEL32.DLL and it will not start up on Windows 2000. The links above show how to check the Windows version and how to dynamically load DLLs and import functions. // Works only on Windows 95,98 and ME. // The kernels of Windows NT/2000/XP do not export this function function RegisterServiceProcess(dwProcessID, dwType: DWORD): DWORD; stdcall; external 'KERNEL32.DLL'; begin // hide by registering as a service RegisterServiceProcess(GetCurrentProcessID, 1); // show again RegisterServiceProcess(GetCurrentProcessID, 0); end