IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Discussion :

service : Problème de détection du redemarrage


Sujet :

Windows

  1. #1
    Nouveau membre du Club
    Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2007
    Messages : 55
    Points : 30
    Points
    30
    Par défaut service : Problème de détection du redemarrage
    Bonjour,

    J'ai besoin de detecter un redemarrage dans un service
    Config : XP sp3 32 bits.

    j'ai le code suivant et dans la msdn il est bien precisé que SERCIVE_CONTROL_SHUTDOWN est un control code du handler que j'ai codé.
    mais ça ne marche pas.

    j'utilise la fonction : RegisterServiceCtrlHandlerEx avec son Handler appelé serviceCtrlHandler que j'appel dans le serviceMain() comme suit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    void WINAPI ServiceController::serviceMain(DWORD aArgc, LPTSTR *aArgv)
    {
    	if(IsEnabledLogs())
    	{
    		LCEnableTrace(true);
    	}
    	LCGetLogFileName("App.log");
    	LCTrace("run App deamon");
    
    	gServiceSingleton = getServiceSingleton();
    
    	//-----	initialise service status	-----
    	gServiceSingleton->mServiceStatus.dwServiceType				= SERVICE_WIN32;
    	gServiceSingleton->mServiceStatus.dwCurrentState				= SERVICE_START_PENDING;
    	gServiceSingleton->mServiceStatus.dwControlsAccepted			= SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_PAUSE_CONTINUE;
    	gServiceSingleton->mServiceStatus.dwWin32ExitCode				= 0;
    	gServiceSingleton->mServiceStatus.dwServiceSpecificExitCode		= 0;
    	gServiceSingleton->mServiceStatus.dwCheckPoint					= 0;
    	gServiceSingleton->mServiceStatus.dwWaitHint					= 0;
    
    	gServiceSingleton->mLoopThreadID = GetCurrentThreadId();
    
    	gServiceSingleton->mServiceStatusHdl = RegisterServiceCtrlHandlerEx(kServiceName, serviceCtrlHandler, gServiceSingleton);
    	if(!gServiceSingleton->mServiceStatusHdl)
    	{
    		return;
    	}
    
    
    	//----- Main loop -----
    	MSG lMsg;
    	lMsg.message=0;
    	DWORD lStatus;
    	while(lMsg.message!=kStopServiceMessage)
    	{
    		LCTrace("waiting for msg/evt in main loop...");
    		lStatus=MsgWaitForMultipleObjectsEx(0,NULL,INFINITE,QS_ALLINPUT,MWMO_ALERTABLE);
    		if(lStatus==WAIT_OBJECT_0)
    		{
    			while(PeekMessage(&lMsg, NULL, 0,0,PM_REMOVE))
    			{
    				if(lMsg.message==kStopServiceMessage)
    					break;
    				if(lMsg.message==SERVICE_CONTROL_SESSIONCHANGE)
    				{
    					gServiceSingleton->mDeviceNotifier->lockDeviceWhenPowerCallback(lMsg.wParam,lMsg.lParam);
    				}
    				if(lMsg.message==SERVICE_CONTROL_SHUTDOWN)
    				{
    					gServiceSingleton->mDeviceNotifier->lockDeviceWhenPowerCallback(lMsg.wParam,lMsg.lParam);
    				}
    				else
    				{
    					TranslateMessage(&lMsg);
    					DispatchMessage(&lMsg);
    				}
    			}
    		}
    	}
    
    }
    et voici le Handler ou j'ai différent control control dont le SHUTDOWN dans un switch :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    DWORD WINAPI ServiceController::serviceCtrlHandler(DWORD aCtrlCode, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
    {
    	DWORD lResult = NO_ERROR;
    	
    	FILE* file = fopen(".\\tmp\\test.txt","w");
    	if(file)
    	{
    		fprintf(file,"Control code : %d\n",aCtrlCode);
    	}
    
    	switch(aCtrlCode)
    	{
    		case SERVICE_CONTROL_PAUSE:
    		case SERVICE_CONTROL_CONTINUE:
    			break;
    		case SERVICE_CONTROL_SHUTDOWN:
    			PostThreadMessage(gServiceSingleton->mLoopThreadID, SERVICE_CONTROL_SHUTDOWN , dwEventType,(LPARAM)lpEventData);
    			break;
    		case SERVICE_CONTROL_STOP:
    			PostThreadMessage(gServiceSingleton->mLoopThreadID, kStopServiceMessage, 0, 0);
    			gServiceSingleton->mServiceStatus.dwCurrentState	= SERVICE_STOP_PENDING;
    			gServiceSingleton->mServiceStatus.dwWin32ExitCode	= 0;
    			gServiceSingleton->mServiceStatus.dwCheckPoint		= 0;
    			gServiceSingleton->mServiceStatus.dwWaitHint		= 1500;	//Wait 1.5s before checking again
    			break;
    
    		case SERVICE_CONTROL_DEVICEEVENT:
    			PostThreadMessage(gServiceSingleton->mLoopThreadID, SERVICE_CONTROL_DEVICEEVENT, dwEventType,(LPARAM)lpEventData);
    			//gServiceSingleton->mDeviceNotifier->deviceChangeCallback(dwEventType,(LPARAM)lpEventData);
    			break;
    		case SERVICE_CONTROL_SESSIONCHANGE:
    			PostThreadMessage(gServiceSingleton->mLoopThreadID, SERVICE_CONTROL_SESSIONCHANGE , dwEventType,(LPARAM)lpEventData);
    			break;
    		default:
    			OutputDebugString(_T("received another control"));
    			lResult = ERROR_CALL_NOT_IMPLEMENTED;
    	}
    
    	SetServiceStatus(gServiceSingleton->mServiceStatusHdl, &gServiceSingleton->mServiceStatus);
    
    	return lResult;
    }

    J'écris dans un fichier pour savoir ce qu'il se passe quand je redémarre et tant qu'à faire je récupère le "control code" mais jamais je ne passe dans le Handler lorsque je redemarre ou que je change de session.

    voici ce que dis la msdn je trouve ça contradictoire :

    http://msdn.microsoft.com/en-us/libr...41(VS.85).aspx

    Merci de votre Aide

    Robux.

  2. #2
    Nouveau membre du Club
    Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2007
    Messages : 55
    Points : 30
    Points
    30
    Par défaut
    Il me semble que je dois changer cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    gServiceSingleton->mServiceStatus.dwControlsAccepted			= SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_PAUSE_CONTINUE;
    par celle ci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    gServiceSingleton->mServiceStatus.dwControlsAccepted			= SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_PAUSE_CONTINUE|SERVICE_CONTROL_SHUTDOWN|SERVICE_CONTROL_SESSIONCHANGE;
    Je test et je vous dis.

    Merci

    Robux

  3. #3
    Nouveau membre du Club
    Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2007
    Messages
    55
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Septembre 2007
    Messages : 55
    Points : 30
    Points
    30
    Par défaut
    c'était bien ça

Discussions similaires

  1. problème de détection de boutons radios
    Par boss_gama dans le forum ASP
    Réponses: 2
    Dernier message: 14/06/2006, 11h49
  2. [C# 2.0, Service]Problème service et Timer
    Par boleduch dans le forum Windows Forms
    Réponses: 1
    Dernier message: 25/04/2006, 15h00
  3. [UBUNTU] Problème de détection souris/clavier
    Par Merlin dans le forum Ubuntu
    Réponses: 4
    Dernier message: 19/04/2006, 19h23
  4. [FAQ]problème de détection réseau.
    Par mickael777 dans le forum MFC
    Réponses: 6
    Dernier message: 13/05/2005, 14h43
  5. Problème de détection de nouveau processeur
    Par zakfa dans le forum Composants
    Réponses: 12
    Dernier message: 24/01/2005, 17h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo