Library tutorials & articles

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!

Comments

  1. 12 Aug 2008 at 09:16
    I have got a Problem in code. Unable to find an entry point named 'RegisterServiceProcess' in DLL 'kernel32.dll'.
  2. 04 Nov 2004 at 23:14

    i got teh same problem!!!

  3. 25 Mar 2004 at 14:12

    I get the error: 453: Can't find DLL entry point RegisterServiceProcess in kernel32.
    What does this mean?
    How do I fix it?


    You have written this:
    "As always, mail me if you have any comments or questions"
    How can we email you, when your email is hidden?

  4. 24 Jul 2003 at 07:55
    Yes, it is.
    The reason I didnt code it that way was to keep the example simpler, though I admit that this did make it a little longer and less elegant.
    Primarily, I wanted to focus on the API call I wanted to explain.
    However, now that I see it in black and white, I kinda like it.
    So may be I'll go ahead and modify my code.
    Thanks
  5. 10 Jun 2003 at 17:57

    Private Sub MakeUnmake(MakeOrNot As Boolean)


    Dim pid As Long
    Dim regserv As Long


    If MakeOrNot = True Then
     pid = GetCurrentProcessId()
     regserv = RegisterServiceProcess(pid, RSPSIMPLESERVICE)
    Else
     pid = GetCurrentProcessId()
     regserv = RegisterServiceProcess(pid, RSPUNREGISTERSERVICE)
    End If


    End Sub

  6. 17 Apr 2003 at 06:08

    eh?

  7. 16 Apr 2003 at 02:50

    vc

  8. 07 Apr 2003 at 15:59
    i think the four series articles were very good guide to help me have more knowledge about visual basic API programming i tried to find some but didnt find any but here.
    i really thank you for this arguement but next time use another examples than the allapi viewr?? )
    but anyway i read all the allapi viewer api functions and i know whats there right now and it s really good in addition of being confusing
  9. 01 Jan 1999 at 00:00

    This thread is for discussions of API Programming Series #4.

Leave a comment

Sign in or Join us (it's free).

Sreejath S. Warrier
AddThis

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!