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

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: Stopping Service with Win32::StopService
by JasonDavis (Novice) on Jul 01, 2008 at 00:27 UTC
    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.