|
// *********************************************************
// サービス停止
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxNTService::Stop( LboxString *LService )
{
return LboxNTService::Stop(
LService->szLboxString
);
}
BOOL LboxNTService::Stop( LPTSTR lpService )
{
SC_HANDLE hSCManager;
SC_HANDLE hService;
hSCManager = OpenSCManager(
this->lpMachineName,
NULL,
SC_MANAGER_ALL_ACCESS
);
if ( hSCManager == NULL ) {
return false;
}
hService = OpenService(
hSCManager,
lpService,
SERVICE_STOP | SERVICE_QUERY_STATUS
);
CloseServiceHandle( hSCManager );
if ( hService == NULL ) {
return false;
}
SERVICE_STATUS sc_sts;
BOOL bRet;
bRet = QueryServiceStatus( hService, &sc_sts );
if ( !bRet ) {
CloseServiceHandle( hService );
return false;
}
if ( sc_sts.dwCurrentState == SERVICE_STOPPED ) {
CloseServiceHandle( hService );
return false;
}
bRet = ControlService(
hService,
SERVICE_CONTROL_STOP,
&sc_sts
);
if ( !bRet ) {
CloseServiceHandle( hService );
return false;
}
CloseServiceHandle( hService );
return true;
}
| |