API Programming Series #4

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 can 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!

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Linux is only free if your time has no value” - Jamie Zawinski