#-----------------------------------------------------------------------------------#
# Show_Service.pl displays information about services on a remote machine #
# by Thomas Berger: http://members.aol.com/bergert #
# #
# Ver 1.00 23-Jan-2004 first release #
# Ver 1.01 09-Jul-2004 fixed check for "\\" in server name #
# added startup = 5 (check for no registry key) #
# added state = 8 (undefined) #
# added ServiceType; have yet to find what it means #
# #
#-----------------------------------------------------------------------------------#
use Win32::Service;
use Win32::Registry;
my ($key, %service);
my %status;
%state = (
0 => 'unknown',
1 => 'stopped',
2 => 'starting',
3 => 'stopping',
4 => 'running',
5 => 'resuming',
6 => 'pausing',
7 => 'paused',
8 => 'undefined', # used only by Show_Service.pl
);
%startup = (
0 => 'unknown',
1 => 'kernel driver',
2 => 'automatic startup',
3 => 'manual startup',
4 => 'startup disabled',
5 => 'no registry key', # used only by Show_Service.pl
);
%type = (
0 => 'unknown',
16 => 'unknown',
32 => 'unknown',
272 => 'unknown',
288 => 'unknown',
);
if (@ARGV != 1) {
$server = Win32::NodeName();
}
else {
$server = $ARGV[0];
if (substr($server,0,2) eq "\\\\") {
# strip off backslash
$server = substr($server,2,);
}
}
print "connectiong to machine [$server]\n";
#
# connect to service manager and enumerate services (long name, short name)
#
Win32::Service::GetServices('\\\\'.$server,\%services);
foreach $key (sort keys %services) {
#
# connect to service manager and get service status
#
Win32::Service::GetStatus( '',$services{$key}, \%status);
if (!defined($status{CurrentState})) {
$status{CurrentState} = 8;
}
if (!defined($status{ServiceType})) {
$status{ServiceType} = 0;
}
#foreach $part (keys %status) {
# print " $part : $status{$part}\n";
#}
#
# connect to registry and get service startup mode
#
$HKEY_LOCAL_MACHINE->Win32::Registry::Connect($server,$Remote_Registry_HKLM);
if (!$Remote_Registry_HKLM) {
die "Unable to Connect to HKLM on $server\n";
}
$Remote_Registry_HKLM->Open('System\\CurrentControlSet\\Services\\'.$services{$key},$Reg_Service);
if (!$Reg_Service) {
#die "Unable to Connect to HKLM...Services\\$services{$key} on $server\n";
$value = 5;
}
else {
$Reg_Service->QueryValueEx('Start',$type,$value);
$Reg_Service->Close;
}
$Remote_Registry_HKLM->Close;
print " $key ($services{$key}), $state{$status{CurrentState}}, $startup{$value}, $status{ServiceType}\n";
}