Greetings,
The following script queiries the status of NT services. My question is
there a way to directly query the @servicenames{name} and get the value of a
sub key in that hash? Now I search all {name} keys and continue from there.
Also, how can I get rid of blank line feeds in the input file? The format
is:
Server:Service
If I have more than one \n after the last entry, it tries to test for them!
Thanks,
Bradley
--------------------------------------------
use strict;
use diagnostics;
use Win32::Lanman;
use vars qw(@status %status @servicenames $server $myservice $service);
#Translate error codes to text.
push ( @status, qw(7 Paused 4 Started 3 Stopping 2 Starting 1 Stopped) );
%status = @status;
#Load server/services to be queried.
open( LIST, "c:\\test\\SerSvs.txt" );
while (<LIST>) {
chomp;
( $server, $myservice ) = split (/:/);
if
( !Win32::Lanman::EnumServicesStatus( "\\\\$server", "",
&SERVICE_WIN32,
&SERVICE_STATE_ALL, \@servicenames ) )
{
print "Sorry, something went wrong connecting to $server; error: ";
# get the error code
print Win32::Lanman::GetLastError () . "\n";
}
for $service(@servicenames) {
if ( ${$service}{name} eq "$myservice" ) {
print "$server ${$service}{name}\n";
print "Status $status{${$service}{state}}\n";
}
}
}
close LIST