My beginner code is perhaps laughable but the following works fantastically well for us:
# PROGRAM
# subQueryServiceState.pl
# PURPOSE
# returns the state of each queried service
# DEPENDENCIES
# 1) ActiveState perl,
# AUTHOR
# Daniel Burrow, Alerio Corporation, 9/22/2001 8:19PM
# Command line syntax
# perl -w subQueryServiceState.pl
use Win32::Lanman;
use strict;
my $TestServer = 'YourHostName';
my $TestService = 'YourServiceName';
my $DebugReturn = &queryservicestate($TestServer, $TestService);
print "\nDebugReturn: " . $DebugReturn . "\n";
sub queryservicestate {
use strict;
my ($inServer, $inService) = @_;
print "\ninServer: " . $inServer . " inService: " . $inService . "\n";
my (%Status, $Key, $tmpState, $TextState);
my %State = (
1 => 'not started',
2 => 'starting',
3 => 'stopping',
4 => 'running',
5 => 'continuing',
6 => 'pausing',
7 => 'paused' );
if(!Win32::Lanman::QueryServiceStatus("\\\\$inServer", "", $inService, \%Status)) {
print "Sorry, something went wrong; error: ";
# get the error code
print Win32::Lanman::GetLastError();
};
for $Key (sort keys %Status) {
print "$Key = $Status{$Key}\n";
if ($Status{'state'}) {
$tmpState = $Status{'state'};
$TextState = $State{$tmpState};
};
};
print "\n\t$inServer $inService service is: $TextState \n\n";
return $TextState;
};