windows services

J

Jexxa

Hi, I had a look on cpan for a module to control windows 2000
services. eg turing on and off and status information. Nothing jumped
out at me. Have I found the one area that perl has not infiltrated?
will I have to write my own module?
Any answers or comments gratefully received.
 
J

James Willmore

On 10 Dec 2003 02:09:22 -0800
Hi, I had a look on cpan for a module to control windows 2000
services. eg turing on and off and status information. Nothing
jumped out at me. Have I found the one area that perl has not
infiltrated? will I have to write my own module?
Any answers or comments gratefully received.

Have you looked at Win32::Service?
http://search.cpan.org/~gsar/libwin32-0.191/Service/Service.pm

I'm not 100% sure that ActiveState has a build for this or not. I'm
thinking it does - since it is a Win32 module.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Deliberation, n.: The act of examining one's bread to determine
which side it is buttered on. -- Ambrose Bierce, "The Devil's
<Dictionary"
 
K

ko

Hi, I had a look on cpan for a module to control windows 2000
services. eg turing on and off and status information. Nothing jumped
out at me. Have I found the one area that perl has not infiltrated?
will I have to write my own module?
Any answers or comments gratefully received.

Hmm...a CPAN search on 'windows service' turns up Win32::Service as
the *second* result...

Anyway, here's a link with some example scripts:

http://www.winnetmag.com/Articles/ArticleID/16069/pg/1/1.html

HTH - keith
 
J

Jexxa

Hmm...a CPAN search on 'windows service' turns up Win32::Service as
the *second* result...

Anyway, here's a link with some example scripts:

http://www.winnetmag.com/Articles/ArticleID/16069/pg/1/1.html

HTH - keith

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
 
K

ko

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
 
J

Jexxa

ko said:
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

solved my problem of not getting back the status info. I had to use
the value rather than the key of the hash returned by GetServices. Not
sure why all the documentation says key. maybe its because its windows
2000. but then it still works when I interrogate NT4 machines from my
win 2000 box.
Thanks for all the help

Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,081
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top