1 | package Win32::Service;
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Service.pm
|
---|
5 | # Written by [email protected]
|
---|
6 | #
|
---|
7 | # subsequently hacked by Gurusamy Sarathy <[email protected]>
|
---|
8 | #
|
---|
9 |
|
---|
10 | $VERSION = '0.05';
|
---|
11 |
|
---|
12 | require Exporter;
|
---|
13 | require DynaLoader;
|
---|
14 |
|
---|
15 | die "The Win32::Service module works only on Windows NT" if(!Win32::IsWinNT());
|
---|
16 |
|
---|
17 | @ISA= qw( Exporter DynaLoader );
|
---|
18 | @EXPORT_OK =
|
---|
19 | qw(
|
---|
20 | StartService
|
---|
21 | StopService
|
---|
22 | GetStatus
|
---|
23 | PauseService
|
---|
24 | ResumeService
|
---|
25 | GetServices
|
---|
26 | );
|
---|
27 |
|
---|
28 | =head1 NAME
|
---|
29 |
|
---|
30 | Win32::Service - manage system services in perl
|
---|
31 |
|
---|
32 | =head1 SYNOPSIS
|
---|
33 |
|
---|
34 | use Win32::Service;
|
---|
35 |
|
---|
36 | =head1 DESCRIPTION
|
---|
37 |
|
---|
38 | This module offers control over the administration of system services.
|
---|
39 |
|
---|
40 | =head1 FUNCTIONS
|
---|
41 |
|
---|
42 | =head2 NOTE:
|
---|
43 |
|
---|
44 | All of the functions return false if they fail, unless otherwise noted.
|
---|
45 | If hostName is an empty string, the local machine is assumed.
|
---|
46 |
|
---|
47 | =over 10
|
---|
48 |
|
---|
49 | =item StartService(hostName, serviceName)
|
---|
50 |
|
---|
51 | Start the service serviceName on machine hostName.
|
---|
52 |
|
---|
53 | =item StopService(hostName, serviceName)
|
---|
54 |
|
---|
55 | Stop the service serviceName on the machine hostName.
|
---|
56 |
|
---|
57 | =item GetStatus(hostName, serviceName, status)
|
---|
58 |
|
---|
59 | Get the status of a service. The third argument must be a hash
|
---|
60 | reference that will be populated with entries corresponding
|
---|
61 | to the SERVICE_STATUS structure of the Win32 API. See the
|
---|
62 | Win32 Platform SDK documentation for details of this structure.
|
---|
63 |
|
---|
64 | =item PauseService(hostName, serviceName)
|
---|
65 |
|
---|
66 | =item ResumeService(hostName, serviceName)
|
---|
67 |
|
---|
68 | =item GetServices(hostName, hashref)
|
---|
69 |
|
---|
70 | Enumerates both active and inactive Win32 services at the specified host.
|
---|
71 | The hashref is populated with the descriptive service names as keys
|
---|
72 | and the short names as the values.
|
---|
73 |
|
---|
74 | =back
|
---|
75 |
|
---|
76 | =cut
|
---|
77 |
|
---|
78 | sub AUTOLOAD
|
---|
79 | {
|
---|
80 | my($constname);
|
---|
81 | ($constname = $AUTOLOAD) =~ s/.*:://;
|
---|
82 | #reset $! to zero to reset any current errors.
|
---|
83 | local $! = 0;
|
---|
84 | my $val = constant($constname);
|
---|
85 | if ($! != 0) {
|
---|
86 | if($! =~ /Invalid/) {
|
---|
87 | $AutoLoader::AUTOLOAD = $AUTOLOAD;
|
---|
88 | goto &AutoLoader::AUTOLOAD;
|
---|
89 | }
|
---|
90 | else {
|
---|
91 | ($pack,$file,$line) = caller;
|
---|
92 | die "Your vendor has not defined Win32::Service macro $constname, used in $file at line $line.";
|
---|
93 | }
|
---|
94 | }
|
---|
95 | eval "sub $AUTOLOAD { $val }";
|
---|
96 | goto &$AUTOLOAD;
|
---|
97 | }
|
---|
98 |
|
---|
99 | bootstrap Win32::Service;
|
---|
100 |
|
---|
101 | 1;
|
---|
102 | __END__
|
---|