AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

Hiding your Application from the Win9x Alt-Ctrl-Del list
 
by Sreejath


Foreword
This article deals with hiding an Application from the Windows task list.
As developers, we often feel the need to run certain applications that provide support services to another application. In such cases it is desirable that this support application doesn't show up in the Alt-Ctrl-Del list (also called the "hit-list") as this may enable the user to kill it causing an application/system crash. In this article we'll discuss how to achieve this in a VB application using API programming.

Note: The technique here is applicable only to Win9x/ME machines. It will not work on NT/2k machines. This is because the Alt-Ctrl-Del list in NT shows both processes and services.
Here the key concept to be understood is this: The task list, while showing the currently running "tasks" on a machine, does not display those registered as services. So to prevent a task from appearing in the task list, register it as a service. And to make the task appear in the task list again, unregister it. Simple!
Let's get on with the code.
As always, start up Visual Basic and create a new Standard EXE project. 
A form (Form1) should have been added to the project by default.
Copy this code into the declarations section of the form:

Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, _
ByVal dwType As Long) As Long

Private Const RSP_SIMPLE_SERVICE = 1
Private Const RSP_UNREGISTER_SERVICE = 0

Create a new procedure to the form, called "MakeService". 
Add the following code to this procedure:

Dim pid As Long
Dim lngRet As Long
pid = GetCurrentProcessId()
lngRet = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)

To remove your program from the Ctrl+Alt+Delete add this code to call the procedure:

Call MakeService

This can be called from any procedure in the form.
Now press Alt-Ctrl-Del and you’ll see that our app is not visible in the list.
To make your program appear in the task list again:
Create a new procedure to the form, called "MakeProcess". 
Add the following code to this procedure:

Dim pid As Long
Dim lngRet As Long
pid = GetCurrentProcessId()
lngRet = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)

To unregister your application as a service (and therefore show the program in the Ctrl+Alt+Delete 
task list), add this code to call the procedure:

Call MakeProcess

Now press Alt-Ctrl-Del and you’ll see that our app is again visible in the list.

Analysis
Let us try to understand what we've been doing here.
First we declared the necessary API calls. (For more information re: how to declare and use API functions, see Article#2- Using API in VB. For more information regarding API Programming see Article#1 What is Windows API?)
Here we need three API calls.

1) GetCurrentProcessId This call, which doesn't accept any parameters, returns the ProcessID of the current process. The ProcessID is a unique Long value that Windows assigns to a process.

2) GetCurrentProcess This call returns a handle to the current process and is used by the GetCurrentProcessId function in determining the ProcessID.

3) RegisterServiceProcess This call accepts the ProcessID of a process and a type parameter. It then registers/unregisters the process (whose ID is given) as a service depending on the value of the type parameter. The type parameter can be either RSP_SIMPLE_SERVICE(= 1) in which case the process is registered as a simple service (it no longer appears in the task list) or RSP_UNREGISTER_SERVICE (= 0), in which case the process is unregistered as a service (appears in the task list). Both these constants are declared in the General | 
Declarations section.

Now, whenever we want to register a service as a process, we retrieve its ProcessID, pass it to the RegisterServiceProcess along with the dwType argument set to RSP_SIMPLE_SERVICE. And when we want to unregister it, do the same thing but this time set the dwType parameter to RSP_UNREGISTER_SERVICE.

For convenience, we have put all the necessary code in two separate procedures and call these procedures as necessary.

That's all for now. As always, mail me if you have any comments or questions
Good-bye, Good luck and happy coding!

1 - 2 - 3 - 4 - 5
Back to Tutorials - Main

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/