SERVICE_INTERACTIVE_PROCESS problems.

mwp_ocau
mwp_ocau used Ask the Experts™
on
Greetings....

I am having troubles getting my NT service to be able to access the desktop.
My code is below.... the service seems to stop at the MessageBox line and does not display the message box to the desktop.
Its compiled under VC6.

Any ideas?
Thanks in advance.

//---------------------------------------------------------------------------
void service_main(int argc, char **argv)
{
      //setup the handler
      status_handle = RegisterServiceCtrlHandler("TextService", (LPHANDLER_FUNCTION)service_handler);
      if (status_handle == 0)
            return;

      // service init
      service_status.dwServiceType            = SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS;
      service_status.dwCurrentState            = SERVICE_RUNNING;
      service_status.dwControlsAccepted      = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
      service_status.dwWin32ExitCode            = NO_ERROR;
      service_status.dwServiceSpecificExitCode = 0;
      service_status.dwCheckPoint            = 0;
      service_status.dwWaitHint            = 0;
      
      // report the current state
      if (SetServiceStatus(status_handle, &service_status) == 0)
            return;

      //testing
      MessageBox(NULL, "Run", "Service", MB_OK);

      //run the main thread
      terminated = false;
      BYTE ret = execute_cc2(&terminated);

      //report as stopped
      service_status.dwCurrentState = SERVICE_STOPPED;
      if (ret != 0)
            service_status.dwWin32ExitCode = ret;
      else
            service_status.dwWin32ExitCode = NO_ERROR;
      SetServiceStatus(status_handle, &service_status);
}
//---------------------------------------------------------------------------
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
jkr
Top Expert 2012

Commented:
You have to specify 'SERVICE_INTERACTIVE_PROCESS' when calling 'CreateService()'. It has no effect with 'SetServiceStatus()'.

Author

Commented:
Im using StartServiceCtrlDispatcher() though?
Top Expert 2012
Commented:
>>Im using StartServiceCtrlDispatcher() though?

That makes no difference -  'SERVICE_INTERACTIVE_PROCESS' has to be set when _installing_ the service, not on startup. Alternatively, you could set that using 'ChangeServiceConfig()', but that will also not apply to a running instance of the service.

Author

Commented:
Ahhhh i see.

Thanks a lot.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial