Thread: RegisterServicesProcess

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    22

    RegisterServicesProcess

    Hello,

    I am currently programming in Windows XP. I would like to make a program I created continue running even after users have logged off. The MSDN documentation on this function i.e:

    http://msdn.microsoft.com/library/de...5func_3t0z.asp

    tells me that:

    "To call RegisterServiceProcess, retrieve a function pointer using GetProcAddress on KERNEL32.DLL. Use the function pointer to call RegisterServiceProcess"

    and I quote (to the letter!). This is what I did:

    ------------------------------------------------------------------------
    HMODULE hMod;
    FARPROC ServiceProcess;

    hMod = LoadLibrary("location-of-kernel32.dll");

    if(!hMod) {
    // Never reaches here, always, the module is loaded
    }
    // The problematic stage
    ServiceProcess = GetProcAddres(hMod, "RegisterServiceProcess");

    //ServiceProcess is always NULL
    ----------------------------------------------------------------------

    Does anyone have an idea what the problem could be, is it that the MSDN documentation is rather inaccurate in this or are there permissions in Windows XP that even an administrator (as I am)has to have before loading the library?


    Gerald.
    -------------------------
    Gerald.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    What does GetLastError tell you??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    22
    Sorry, I forgot to include this, but well GetLastError() says error 127 which according to my list of system error codes means:

    127 The specified procedure could not be found. ERROR_PROC_NOT_FOUND

    Gerald
    -------------------------
    Gerald.

  4. #4
    Unregistered
    Guest
    Shouldn't the line that reads:

    hMod = LoadLibrary("location-of-kernel32.dll");


    read instead as:

    hMod = LoadLibrary("kernel32.dll");

    Actually, ignore that, I see the problem.

    Stuff FARPROC - they are a legacy from 16 bit days. What you need is the prototype declaration for the fn you are trying to load from the dll. So yes, ms have given you an example that probably works great with a 386 and win95/NT

    It's a good day to day as I know it:

    typedef DWORD (*REGSERVPROC)(DWORD, DWORD);

    and where you have the line:

    ServiceProcess = GetProcAddress(hMod, "RegisterServiceProcess");

    replace it with:

    ServiceProcess = (REGSERVPROC) GetProcAddress(hMod, "RegisterServiceProcess");

    That should do it.

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    I dont think RegisterServiceProcess is what you are looking for.

    If you want it to run after the person has logged off the PC on XP, i think you'll have to make your program a Service (one that appears in your windows services list).

    good luck
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Uraldor's correct. RegisterServiceProcess() is a 9x function only, which may be why your GetProcAddress is failing.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    22
    Well, I guess Sorensen may be correct about this being a 9x function.

    Are there any ideas about how to make a program a windows service?
    -------------------------
    Gerald.

  8. #8
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    A search of the board got this url -

    http://www.microsoft.com/msj/default...097/newnav.htm

Popular pages Recent additions subscribe to a feed