Service Error 1072

This is a discussion on Service Error 1072 within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, I've written a service and I'm having trouble uninstalling it. Rather than just uninstalling the OS marks the ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    Service Error 1072

    Hi All,

    I've written a service and I'm having trouble uninstalling it. Rather than just uninstalling the OS marks the service for deletion and gives this error if I try and uninstall again:

    ERROR_SERVICE_MARKED_FOR_DELETE

    The initial removal returns no error.

    I know a reboot is a temprary solution.

    What could I be doing wrong?


    Code:
    int MyDeleteService()
    {
    	SC_HANDLE hService,schSCManager;
    	config *my_config;
    
    	if(InitService(my_config))
    	{
    		printf("Error initialising - check config file!\n");
    		return 1;
    	}
    
    	schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
    
    	if (schSCManager == NULL)
    		return GetLastError();
    
    	hService=OpenService(schSCManager,my_config->my_server.serviceName,SERVICE_ALL_ACCESS);
    
    	if (hService == NULL)
    		return GetLastError();
    
    	if(DeleteService(hService)==0)
    		return GetLastError();
    
    	if(CloseServiceHandle(hService)==0)
    		return GetLastError();
    
    	CleanupService();
    
    	return 0;
    }
    Thanks, rotis23

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,765
    I think you need to provide a proper "stop" service as well, otherwise it remains in use until the OS reboots.

    If the stop properly detaches your service from the OS, then there is no reason why it should not be possible to delete it when you de-install it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    When you say stop are you refering to a signal handler?

    I do this:

    Code:
    void ControlHandler(DWORD request)
    {
    	switch(request)
    	{
    		case SERVICE_CONTROL_STOP:
    			CleanupService();
    			ServiceStatus.dwWin32ExitCode = 0;
    			ServiceStatus.dwCurrentState = SERVICE_STOPPED;
    			SetServiceStatus (hStatus, &ServiceStatus);
    			return;
    
    		case SERVICE_CONTROL_SHUTDOWN:
    			CleanupService();
    			ServiceStatus.dwWin32ExitCode = 0;
    			ServiceStatus.dwCurrentState = SERVICE_STOPPED;
    			SetServiceStatus (hStatus, &ServiceStatus);
    			return;
    
    		default:
    			break;
    	}
    
    	// Report current status
    	SetServiceStatus (hStatus, &ServiceStatus);
    }
    I think you're right though - I've read that it will remain in the 'Service Table' until all handles are freed. As far as I'm aware I'm freeing all handles.

    Thanks for your reply.
    Last edited by rotis23; 09-21-2004 at 02:23 PM.

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Sorry - the service was still sleeping in the main loop. I've changed the sleeping mechanism.

    rotis23

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Spoke too soon - The service is stopping correctly now - closing and cleaning up.

    But I still can't delete the service.

    Upon what conditions will the service still be 'attached'?

    If I install the service and remove it - it is deleted OK.

    If I run the service then it does not delete OK afterwards.

    What could I be leaving open in ServiceMain? There are no SC_HANDLE structure to close!

    rotis23

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Hi rotis23,

    I've created my own service last week and it's working fine. I also had the same problem but found out I had the services window still open.

    Here is my version of the un-install:
    Code:
    void UninstallService()
    {
       SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CONNECT);
    
       if(serviceControlManager)
       {
          SC_HANDLE service = OpenService( serviceControlManager,
             serviceName, SERVICE_QUERY_STATUS | DELETE);
    
          if(service)
          {
             SERVICE_STATUS serviceStatus;
             if(QueryServiceStatus( service, &serviceStatus))
             {
                if(serviceStatus.dwCurrentState == SERVICE_STOPPED)
                   DeleteService(service);
             }
             CloseServiceHandle(service);
          }
          CloseServiceHandle(serviceControlManager);
       }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. running my program as service
    By daher in forum Windows Programming
    Replies: 5
    Last Post: 09-05-2008, 01:30 PM
  2. Windows service status checking
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-01-2008, 09:19 AM
  3. eek a virus
    By MisterSako in forum Tech Board
    Replies: 17
    Last Post: 06-08-2005, 04:29 PM
  4. Replies: 1
    Last Post: 06-03-2005, 02:03 AM
  5. Another windows service question... starting/stopping
    By BrianK in forum Windows Programming
    Replies: 1
    Last Post: 03-20-2003, 12:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21