# ntsvcls.pl: NT Service lister
#
#   Perl script to list the services installed on a
#   given server.
#
#   Usage: ntvsvcls.pl server1 server2 ... serverN
#
#   Written By Elfyn mcBratney <elfyn@exposure.org.uk>
#
# Copyright 1999, 2000, 2001, 2002 Elfyn McBratney.
# All Rights Reserved.

BEGIN
{
	use strict;
	use Win32::Service qw(StartService StopService GetStatus GetServices);
}

my %staHash =
(
	'1' => 'stopped.',
	'2' => 'start pending.',
	'3' => 'stop pending.',
	'4' => 'running.',
	'5' => 'continue pending.',
	'6' => 'pause pending.',
	'7' => 'paused.'
);
my %svcHash;
my ($service,%statusHash,$server);

foreach $server (@ARGV)
{
	print "\n--- NT Services on $server ---\n\n";
    GetServices($server, \%svcHash) or next;
    foreach(sort keys %svcHash)
    {
        print "$_: $svcHash{$_}\t";
        &getstatus($server, $_);
    }
}

sub getstatus
{
	GetStatus("$_[0]", "$_[1]", \%statusHash);
	print "$staHash{$statusHash{\"CurrentState\"}} \n";
}



