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

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.
  • Comment on Re^4: Stopping Service with Win32::StopService

Replies are listed 'Best First'.
Re^5: Stopping Service with Win32::StopService
by BrowserUk (Patriarch) on Jul 01, 2008 at 03:41 UTC

    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.