in reply to Re: Stopping Service with Win32::StopService
in thread Stopping Service with Win32::StopService

Thank you very much. Your advice makes it a lot easier to understand compared to what I was doing before. Is there anyway to test that the service has indeed stopped? or check that it isn't stopped to begin with? Regards, Jason.
  • Comment on Re^2: Stopping Service with Win32::StopService

Replies are listed 'Best First'.
Re^3: Stopping Service with Win32::StopService
by BrowserUk (Patriarch) on Jun 30, 2008 at 03:39 UTC
    Is there anyway to test that the service has indeed stopped? or check that it isn't stopped to begin with?

    Type net start at a command prompt and it will list the services that are currently running.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I know about net start, but I was wondering if there is a way I could check in the program itself, so it would check if its stopped to begin with and if so output a message otherwise attempt to stop it and if successful output a message saying it is stopped otherwise output an error message. Thanks for the help so far. Jason.

        It's pretty simple to parse the output of the sc query servicename command:

        C:\test>sc query pgsql-8.2 SERVICE_NAME: pgsql-8.2 TYPE : 10 WIN32_OWN_PROCESS STATE : 4 RUNNING (STOPPABLE,PAUSABLE,ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0

        You can also query this information using DBI, DBD::WMI and the bastardised WQL, but I find structure of WMI unfathomable and the documentation abysmal.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.