本文整理汇总了C++中SetServiceStatus函数的典型用法代码示例。如果您正苦于以下问题:C++ SetServiceStatus函数的具体用法?C++ SetServiceStatus怎么用?C++ SetServiceStatus使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetServiceStatus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ServiceCtrlHandler
VOID WINAPI ServiceCtrlHandler(DWORD fdwControl)
{
switch (fdwControl) {
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
status.dwCurrentState = SERVICE_STOPPED;
break;
default:
break;
}
if (SetServiceStatus(hStatus, &status) == 0) {
printf("Cannot set service status (0x%08x)\n", GetLastError());
exit(1);
}
return;
}
示例2: lutil_ReportShutdownComplete
void lutil_ReportShutdownComplete( )
{
if ( is_NT_Service )
{
/* stop sending SERVICE_STOP_PENDING messages to the Service Control Manager */
ldap_pvt_thread_cond_signal( &stopped_event );
ldap_pvt_thread_cond_destroy( &stopped_event );
/* wait for the thread sending the SERVICE_STOP_PENDING messages to the Service Control Manager to die.
* if the wait fails then put ourselves to sleep for half the Service Control Manager update interval */
if (ldap_pvt_thread_join( stop_status_tid, (void *) NULL ) == -1)
ldap_pvt_thread_sleep( SCM_NOTIFICATION_INTERVAL / 2 );
lutil_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
lutil_ServiceStatus.dwCheckPoint++;
lutil_ServiceStatus.dwWaitHint = SCM_NOTIFICATION_INTERVAL;
SetServiceStatus(hlutil_ServiceStatus, &lutil_ServiceStatus);
}
}
示例3: sendStatusToSCMgr
BOOL sendStatusToSCMgr(DWORD dwCurrentState,
DWORD dwWin32ExitCode,
DWORD dwCheckPoint,
DWORD dwWaitHint) {
BOOL result;
if (dwCurrentState == SERVICE_START_PENDING)
serviceStatus.dwControlsAccepted = 0;
else
serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP |
SERVICE_ACCEPT_PAUSE_CONTINUE;
serviceStatus.dwCurrentState = dwCurrentState;
serviceStatus.dwWin32ExitCode = dwWin32ExitCode;
serviceStatus.dwCheckPoint = dwCheckPoint;
serviceStatus.dwWaitHint = dwWaitHint;
if (!(result = SetServiceStatus(serviceStatusHandle, &serviceStatus))) {
logServiceMessage(_T("SetServiceStatus"), EVENTLOG_ERROR_TYPE);
}
return result;
}
示例4: service_handler
/* Service control callback */
void __stdcall service_handler(DWORD fdwControl)
{
switch(fdwControl){
case SERVICE_CONTROL_CONTINUE:
/* Continue from Paused state. */
break;
case SERVICE_CONTROL_PAUSE:
/* Pause service. */
break;
case SERVICE_CONTROL_SHUTDOWN:
/* System is shutting down. */
case SERVICE_CONTROL_STOP:
/* Service should stop. */
service_status.dwCurrentState = SERVICE_STOP_PENDING;
SetServiceStatus(service_handle, &service_status);
run = 0;
break;
}
}
示例5: GetCurrentThreadId
void CServiceModule::Run()
{
HRESULT hr;
_Module.dwThreadID = GetCurrentThreadId();
// If you are running on NT 4.0 or higher you can use the following call
// to make your service free threaded.
// This means that calls come in on a random RPC thread
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Otherwise, for single threaded use
// hr = CoInitialize(NULL);
ATLASSERT(SUCCEEDED(hr));
// In NT 4.0 and higher where DCOM is supported you may wish to initialize
// the security layer. The following code will give you a DCOM service which
// would allow ALL users access to objects
CSecurityDescriptor sd;
sd.InitializeFromThreadToken();
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL);
ATLASSERT(SUCCEEDED(hr));
// If you wish to have your object creatable remotely using DCOM use the following
hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);
// Otherwise, only local activation
// hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
ATLASSERT(SUCCEEDED(hr));
LogEvent(_T("Service started"));
SetServiceStatus(SERVICE_RUNNING);
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
DispatchMessage(&msg);
_Module.RevokeClassObjects();
CoUninitialize();
}
示例6: ServiceControlHandler
static DWORD WINAPI
ServiceControlHandler(DWORD dwControl,
DWORD dwEventType,
LPVOID lpEventData,
LPVOID lpContext)
{
DPRINT1("ServiceControlHandler() called\n");
switch (dwControl)
{
case SERVICE_CONTROL_STOP:
DPRINT1(" SERVICE_CONTROL_STOP received\n");
SetEvent(ShutdownEvent);
UpdateServiceStatus(SERVICE_STOP_PENDING);
return ERROR_SUCCESS;
case SERVICE_CONTROL_PAUSE:
DPRINT1(" SERVICE_CONTROL_PAUSE received\n");
UpdateServiceStatus(SERVICE_PAUSED);
return ERROR_SUCCESS;
case SERVICE_CONTROL_CONTINUE:
DPRINT1(" SERVICE_CONTROL_CONTINUE received\n");
UpdateServiceStatus(SERVICE_RUNNING);
return ERROR_SUCCESS;
case SERVICE_CONTROL_INTERROGATE:
DPRINT1(" SERVICE_CONTROL_INTERROGATE received\n");
SetServiceStatus(ServiceStatusHandle,
&ServiceStatus);
return ERROR_SUCCESS;
case SERVICE_CONTROL_SHUTDOWN:
DPRINT1(" SERVICE_CONTROL_SHUTDOWN received\n");
SetEvent(ShutdownEvent);
UpdateServiceStatus(SERVICE_STOP_PENDING);
return ERROR_SUCCESS;
default :
DPRINT1(" Control %lu received\n");
return ERROR_CALL_NOT_IMPLEMENTED;
}
}
示例7: OssecServiceCtrlHandler
/** VOID WINAPI OssecServiceCtrlHandler (DWORD dwOpcode)
* "Signal" handler
*/
VOID WINAPI OssecServiceCtrlHandler(DWORD dwOpcode)
{
switch(dwOpcode)
{
case SERVICE_CONTROL_STOP:
ossecServiceStatus.dwCurrentState = SERVICE_STOPPED;
ossecServiceStatus.dwWin32ExitCode = 0;
ossecServiceStatus.dwCheckPoint = 0;
ossecServiceStatus.dwWaitHint = 0;
verbose("%s: Received exit signal.", ARGV0);
SetServiceStatus (ossecServiceStatusHandle, &ossecServiceStatus);
verbose("%s: Exiting...", ARGV0);
return;
default:
break;
}
return;
}
示例8: service_ctrl_handler
static void WINAPI service_ctrl_handler(DWORD control_code)
{
switch (control_code) {
case SERVICE_CONTROL_INTERROGATE:
break;
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
svc_status.dwCurrentState = SERVICE_STOP_PENDING;
svc_status.dwWaitHint = 2000;
eloop_terminate();
SetEvent(kill_svc);
break;
}
if (!SetServiceStatus(svc_status_handle, &svc_status)) {
printf("SetServiceStatus() failed: %d\n",
(int) GetLastError());
}
}
示例9: ServerCtrlHandler
VOID WINAPI
ServerCtrlHandler(DWORD dwControl,
DWORD dwEventType,
LPVOID lpEventData,
LPVOID lpContext)
{
PSERVICEINFO pServInfo = (PSERVICEINFO)lpContext;
switch (dwControl)
{
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_STOP:
LogEvent(L"\nSetting the service to SERVICE_STOP_PENDING", 0, 0, LOG_FILE);
InterlockedExchange((LONG *)&bShutdown, TRUE);
pServInfo->servStatus.dwWin32ExitCode = 0;
pServInfo->servStatus.dwWaitHint = 5000;
UpdateStatus(pServInfo, SERVICE_STOP_PENDING, 1);
break;
case SERVICE_CONTROL_PAUSE: /* not yet implemented */
LogEvent(L"Setting the service to SERVICE_PAUSED", 0, 0, LOG_FILE);
InterlockedExchange((LONG *)&bPause, TRUE);
UpdateStatus(pServInfo, SERVICE_PAUSED, 0);
break;
case SERVICE_CONTROL_CONTINUE:
LogEvent(L"Setting the service to SERVICE_RUNNING", 0, 0, LOG_FILE);
InterlockedExchange((LONG *)&bPause, FALSE);
UpdateStatus(pServInfo, SERVICE_RUNNING, 0);
break;
case SERVICE_CONTROL_INTERROGATE:
SetServiceStatus(pServInfo->hStatus, &pServInfo->servStatus);
break;
default:
if (dwControl > 127 && dwControl < 256) /* user defined */
LogEvent(L"User defined control code", 0, 0, LOG_FILE);
else
LogEvent(L"ERROR: Bad control code", 0, 0, LOG_FILE);
break;
}
}
示例10: GetCurrentThreadId
void CServiceModule::Run()
{
_Module.dwThreadID = GetCurrentThreadId();
HRESULT hr = CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call
// instead to make the EXE free threaded.
// This means that calls come in on a random RPC thread
// HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
_ASSERTE(SUCCEEDED(hr));
// This provides a NULL DACL which will allow access to everyone.
CSecurityDescriptor sd;
sd.InitializeFromThreadToken();
hr = CoInitializeSecurity(sd, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
_ASSERTE(SUCCEEDED(hr));
hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);
_ASSERTE(SUCCEEDED(hr));
LogEvent(_T("Service started"));
if (m_bService)
SetServiceStatus(SERVICE_RUNNING);
try
{
_ppool = new CDBConnectionPool ();
}
catch (...)
{
goto end;
}
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
DispatchMessage(&msg);
end:
_Module.RevokeClassObjects();
CoUninitialize();
}
示例11: CmdStart
// Start service
VOID WINAPI CmdStart (DWORD, LPTSTR* )
{
DWORD status = 0;
DWORD specificError = 0;
ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
ServiceStatusHandle = RegisterServiceCtrlHandler(
SERVICENAME, CmdCtrlHandler );
if (ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0)
return;
// Initialization complete - report running status.
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
if (!SetServiceStatus (ServiceStatusHandle, &ServiceStatus))
status = GetLastError();
else
{
//we do all things in the thread of _ServiceMain, wo also could do things here
//while(true)
//{
//}
// Start the main thread
g_hServiceEvents[0] = CreateEvent( NULL, FALSE, FALSE, NULL );
g_hServiceEvents[1] = CreateEvent( NULL, FALSE, FALSE, NULL );
g_hServiceEvents[2] = CreateEvent( NULL, FALSE, FALSE, NULL );
_beginthread( _ServiceMain, 0, NULL );
}
return;
}
示例12: ServiceMain
VOID WINAPI ServiceMain(DWORD dwArgc, LPTSTR *lpszArgv)
{
DWORD status = 0;
DWORD specificError = 0xfffffff;
ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_PAUSE_CONTINUE;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
hServiceStatusHandle = RegisterServiceCtrlHandler(pServiceName, ServiceHandler);
if (hServiceStatusHandle==0)
{
long nError = GetLastError();
char pTemp[121];
sprintf_s(pTemp, "RegisterServiceCtrlHandler failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
return;
}
// Initialization complete - report running status
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
if(!SetServiceStatus(hServiceStatusHandle, &ServiceStatus))
{
long nError = GetLastError();
char pTemp[121];
sprintf_s(pTemp, "SetServiceStatus failed, error code = %d\n", nError);
WriteLog(pLogFile, pTemp);
}
AttachProcessNames();
for(int iLoop = 0; iLoop < MAX_NUM_OF_PROCESS; iLoop++)
{
pProcInfo[iLoop].hProcess = 0;
StartProcess(iLoop);
}
}
示例13: ServiceMain
void ServiceMain(int argc, char** argv)
{
HSP sp;
memset(&sp,0,sizeof(sp));
sp.configFile = "";
sp.pidFile = "";
ServiceStatus.dwServiceType = SERVICE_WIN32;
ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
if(!debug){
hStatus = RegisterServiceCtrlHandler(
"hsflowd",
(LPHANDLER_FUNCTION)ControlHandler);
if (hStatus == (SERVICE_STATUS_HANDLE)0)
{
// Registering Control Handler failed
return;
}
}
// report the running status to SCM.
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus (hStatus, &ServiceStatus);
readInterfaces(&sp);
HSPReadConfig(&sp);
initAgent(&sp);
// main loop
while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
{
sfl_agent_tick(sp.sFlow->agent, time(NULL));
Sleep(SLEEP_TIME);
}
return;
}
示例14: ReportStatus
/// 回报服务状态
bool win_svc_base::ReportStatus(unsigned long dwCurrentState, unsigned long dwExitCode
, unsigned long dwCheckPoint, unsigned long dwWaitHint)
{
if (dwCurrentState == SERVICE_START_PENDING)
m_pWinStructImpl->m_ssStatus.dwControlsAccepted = 0;
else
m_pWinStructImpl->m_ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
// Initialize ss structure.
m_pWinStructImpl->m_ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
m_pWinStructImpl->m_ssStatus.dwServiceSpecificExitCode = 0;
m_pWinStructImpl->m_ssStatus.dwCurrentState = dwCurrentState;
m_pWinStructImpl->m_ssStatus.dwWin32ExitCode = dwExitCode;
m_pWinStructImpl->m_ssStatus.dwCheckPoint = dwCheckPoint;
m_pWinStructImpl->m_ssStatus.dwWaitHint = dwWaitHint;
bool bRet = (SetServiceStatus(m_pWinStructImpl->m_ssh, &m_pWinStructImpl->m_ssStatus) ? true : false);
//LOG << "call ReportStatus dwCurrentState=" << dwCurrentState << " ret=" << bRet << std::endl;
return bRet;
}
示例15: switch
//! 服务程序的事件响应入口
VOID WINAPI ServiceControl::ControlHandler(DWORD request)
{
switch (request)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
ServiceSCC::GetInstance().CloseExec();
ServiceSCC::GetInstance().Relese();
c_ServiceStatus.dwCurrentState = SERVICE_STOPPED;
SetServiceStatus(c_hStatus, &c_ServiceStatus);
break;
case SERVICE_CONTROL_PAUSE:
break;
case SERVICE_CONTROL_CONTINUE:
break;
case SERVICE_CONTROL_INTERROGATE:
break;
}
}