Dienst lässt sich nicht stoppen



  • Hallo, ich will einen Service stoppen. Leider klappt dies nicht so wie ich will:

    h = OpenSCManager(NULL,NULL,SERVICE_STOP);
    	   if(h == NULL) {
    		   printf("GetLastError: %i\n",GetLastError());
                       return 1;
               }
    
    	  p = OpenService(h,"wuauserv",SERVICE_STOP);
    	   if(p == NULL) {
    		   printf("GetLastError: %i\n",GetLastError());
                       return 1;
               }
    
    	     err = ControlServiceEx(p,SERVICE_CONTROL_STOP,0,NULL); //hier hängts
                  if(err == 0) {
    		 printf("GetLastError: %i\n",GetLastError());
                     return 1;
                  }
    

    GetLastError sagt mir:

    The system call level is not correct.

    Ich weiß nicht wirklich wo mein Fehler ist da ich den Errorcode nicht wirklich verstehe.
    Freue mich auf hilfe.
    :D:D



  • Oh man, w7sdk->ControlServiceEx

    ERROR_INVALID_PARAMETER: [...] or dwControl is SERVICE_CONTROL_STOP but the dwReason or pszComment members of the SERVICE_CONTROL_STATUS_REASON_PARAMS structure are not valid.

    dwInfoLevel [in]
    The information level for the service control parameters. This parameter must be set to SERVICE_CONTROL_STATUS_REASON_INFO (1).

    pControlParams [in, out]
    A pointer to the service control parameters, this member is a pointer to a SERVICE_CONTROL_STATUS_REASON_PARAMS structure.

    ControlServiceEx(...,0,NULL) ist nich korrekt. Use ControlService.



  • err = ControlService(p,SERVICE_CONTROL_STOP,NULL);
    

    Jetzt erhalte ich den Error Code:

    ERROR_INVALID_ADDRESS
    487 (0x1E7)

    Attempt to access invalid address.



  • Du benötigst als 3. Argument SERVICE_STATUS

    SERVICE_STATUS result;
    memset(&result, 0, sizeof(SERVICE_STATUS));
    
    ...
    
    err = ControlService(p,SERVICE_CONTROL_STOP, &result);
    

Anmelden zum Antworten