Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm not very familiar with NT - how can I determine if a particular service is running from perl? This is on NT 4, not 2000.
  • Comment on determining if a service is alive on a win32 system

Replies are listed 'Best First'.
Re: determining if a service is alive on a win32 system
by barndoor (Pilgrim) on Jun 29, 2000 at 21:10 UTC
    Below is an example of it's use and how to interpret the results:
    use Win32::Service; my %statusHash; Win32::Service::GetStatus("", "EventLog", \%statusHash); print $statusHash{"CurrentState"} . "\n"; # CurrentState can be: # 1 = stopped. # 2 = start pending. # 3 = stop pending. # 4 = running. # 5 = continue pending. # 6 = pause pending. # 7 = paused.
    No error check done, Sorry. As you can see GetStatus uses a hash reference to return the results. This contains other stuff like 'Service Type' and other wierd bits. I tried this code on NT4 SP3 and it works fine.
(jcwren) Re: determining if a service is alive on a win32 system
by jcwren (Prior) on Jun 29, 2000 at 18:15 UTC
    Check out Win32::Service and the other Win32 functions. It allows starting, stopping, and requesting the status of various services.

    --Chris