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.
/* Detach from your current visible console if not using WinMain */
/* Get a handle to kernel32 */
HINSTANCE hKernel = LoadLibrary("KERNEL32.DLL");
if (hKernel == NULL)
/* 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 );
/* 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)
/* Free the kernel library */
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:
and make the string value the path to your executable. Your all set!