typedef UINT (CALLBACK* REG)(DWORD,DWORD); 
BOOL RegSvrProcess(BOOL bReg)   //bReg=true时注册为service
{
HINSTANCE hKernel = ::LoadLibrary("KERNEL32.DLL");
if(!hKernel)
return false;
REG proc = (REG)::GetProcAddress((HMODULE)hKernel,"RegisterServiceProcess");
if(!proc) 
{
FreeLibrary(hKernel);
return false;
}
DWORD retval = (*proc)(NULL,(DWORD)(bReg));
FreeLibrary(hKernel);
return retval;
}

解决方案 »

  1.   

    The RegisterServiceProcess function registers or unregisters a service process. A service process continues to run after the user logs off. DWORD RegisterServiceProcess(DWORD dwProcessId, 
        DWORD dwType);ParametersdwProcessIdSpecifies the identifier of the process to register as a service process. Specifies NULL to register the current process. dwTypeSpecifies whether the service is to be registered or unregistered. This parameter can be one of the following values. Value Meaning
    RSP_SIMPLE_SERVICE Registers the process as a service process.
    RSP_UNREGISTER_SERVICE Unregisters the process as a service process.
     Return ValueThe return value is 1 if successful or 0 if an error occurs.