Jexxa said:
(e-mail address removed) (ko) wrote in message
[snip]
You know you are right. However I'm running on win 2000 and the
service status tends to come back as an empty hash. probably something
in the policy, or something. All I can get is a list of services that
may or may not be running. Some services return status information but
not the ones I am interested in.
Thanks anyway.
Jeremy
Haven't played with the module in while. Also had another link with more
sample scripts, but can't find it now...
Anyway, try this:
use strict;
use warnings;
use Win32::Service qw[GetServices GetStatus];
my (%services, %status);
GetServices('', \%services);
foreach my $service(sort keys %services) {
print "$services{$service} [ $service ]\n";
GetStatus('', $services{$service}, \%status);
foreach (keys %status) {
# remove this for more info
print "\t$_: $status{$_}\n" if $_ eq 'CurrentState';
}
}
When 'CurrentState' has a value of 1, the service is stopped. When the
value is 4, the service is running. See comment in code to get more info
- but as stated in the Win32::Service docs, you'll have to check the
Win32 Platform SDK documentation to see what everything means.
To stop/start a service import StartService()/StopService(), and make
sure that you use the service name (key of the %services hash above) as
the second argument.
HTH -keith