GOFF Home

 
 Windows 9x Services.

I know what your thinking. Windows 9x does not have services!? Well, not like what NT has but it does have the ability to run processes that are invisible to the user. Why would you even be supporting 9x? Well there are still millions of them out there and say for example we need to run a non-gui application before the user logs onto their system. Ok so here is the code with comments.

void Win9xService(void)
{
   /* Detach from your current visible console if not using WinMain */
   FreeConsole();

   /* Get a handle to kernel32 */
   HINSTANCE hKernel = LoadLibrary("KERNEL32.DLL");
   if (hKernel == NULL)
   {
      return;
   }

   /* Get a function pointer to RegisterServiceProcess function within kernel32 */
   FARPROC lpfn = GetProcAddress(hKernel, "RegisterServiceProcess");

   /* Define the function (RegisterServiceProcess) in the dll for reuse */
   typedefDWORD (WINAPI * pICFUNC)(DWORD , DWORD );
   pICFUNC fpRegisterServiceProcess;

   /* Instantiate an instance */
   fpRegisterServiceProcess = pICFUNC(lpfn);

   /* Now use the function pointer we have to register our process as a service */
   if (fpRegisterServiceProcess(GetCurrentProcessId(), 1) == 1)
   {
      return;
   }

   /* Free the kernel library */
   FreeLibrary(hKernel);

   return;
}

Now when you execute this function your console will disappear or if running from the command line you will return. But in order to run before the user logs in you need to edit a Registry key. Add a string type Subkey under:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices
and make the string value the path to your executable. Your all set!
Resources for
Microsoft Exchange
Windows 7 Search


Information
News