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

Hi Brotherens I need to obtain a list of service on a remote machine that have not started. I Used this code below
$|++; use strict; use diagnostics; use Win32::Service; use vars qw/$machine %SSvcLst/; $machine = "\\\\". $ARGV[0]; if (Win32::Service::GetServices($machine,\ %SSvcLst)) { print "\nObtaining list of running services\n"; for my $item (sort ( keys ( %SSvcLst ))) { print "$SSvcLst{$item} = $item\n"; if (Win32::Service::GetStatus($machine ,$SSvcLst{$item},\ my +%status)) { for my $item2 (keys ( %status)) { print "\t\t$item2 = $status{$item2}\n"; } } } }
and the out put that I got is:
Obtaining list of running services Alerter = Alerter CurrentState = 4 ServiceType = 32 CheckPoint = 0 ServiceSpecificExitCode = 0 WaitHint = 0 Win32ExitCode = 0 ControlsAccepted = 1 SeagateAgentBrowser = Backup Exec (TM) 7.0 Agent Browser CurrentState = 4 ServiceType = 16 CheckPoint = 0 ServiceSpecificExitCode = 0 WaitHint = 0 Win32ExitCode = 0 ControlsAccepted = 1 Seagate Alert Server = Backup Exec (TM) 7.0 Alert Server CurrentState = 4 ServiceType = 16 CheckPoint = 0 ServiceSpecificExitCode = 0 WaitHint = 0 Win32ExitCode = 0 ControlsAccepted = 1 Seagate Device & Media Service = Backup Exec (TM) 7.0 Device & Media S +ervice CurrentState = 4 ServiceType = 16 CheckPoint = 0 ServiceSpecificExitCode = 0 WaitHint = 0 Win32ExitCode = 0 ControlsAccepted = 5 Seagate Job Engine = Backup Exec (TM) 7.0 Job Engine CurrentState = 4 ServiceType = 16 CheckPoint = 0 ServiceSpecificExitCode = 0 WaitHint = 0 Win32ExitCode = 0 ControlsAccepted = 5
I assume that the current status is what I am after, however the out put is just an Integer,...can some please tell me what are those numbers equate to?

Replies are listed 'Best First'.
Re: Remote NT services
by Mr. Muskrat (Canon) on Aug 12, 2003 at 18:28 UTC
    Exchange Service Monitor uses the following to describe the various values of the CurrentState returned by Win32::Service::GetStatus:
    %state = ( 0 => "Unknown", 1 => "Stopped", 2 => "Starting", 3 => "Stopping", 4 => "Running", 5 => "Resuming", 6 => "Pausing", 7 => "Paused", );

    Added: There is an article that talks about using Win32::Service. The information in the web-exclusive table is very informative. Also be sure to check the Win32 Platform SDK documentation as pointed out by the module's documentation.

      Thanks for this,...

      What about this "ServiceType = 0, or 272 or 323", will this help me to determine if a service is automatic or manual?
      Thanks.
      PLEASE HELP

      I have just looked at "web-exclusive table " and I can't find anywhere where I can determin if a service is automatic or manual.

      Thanks alot.

        I just posted Check Win32 Service Start Type and I think it might help you. :-)

        You'll need to modify it a little to work with remote servers. Most of what you will need to do is as follows:
        Remove the delimiter argument*, change all forward slashes to double backslashes and then change the line that defines $services to add $machine\\ before HKEY_LOCAL_MACHINE.

        * rather than rewrite portions of your existing script...

Re: Remote NT services
by Mr. Muskrat (Canon) on Aug 12, 2003 at 19:49 UTC

    Here's my interpretation of the info.

    my %ServiceType = ( 1 => 'kernel driver', 2 => 'file system driver', 4 => 'unknown', # perhaps the unknown values 8 => 'unknown', # are defined in the MS docs... 16 => 'own process space', 32 => 'shared process space', 64 => 'unknown', 128 => 'unknown', 256 => 'interactive process', ); my %ControlsAccepted = ( 1 => 'accept stop', # The service can process requests to stop. 2 => 'accept pause/continue', # The service can process requests to +pause and resume (continue) from a paused state. 4 => 'accept shutdown', # The service will receive this message when + the OS shuts down. 8 => 'accept param change', # The service can process changes to the + service's configuration without having to stop. This flag is only ap +plicable on Win2K (and later) platforms. ); my @types = (272,323); # two example ServiceTypes to check out for my $type (@types) { print "ServiceType: $type "; for my $key (keys %ServiceType) { print $ServiceType{$key},", " if ($type & $key); } print "\n"; }