File Coverage

blib/lib/Win32/NetSend.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Win32::NetSend;
2            
3             our $VERSION="0.02";
4             #our $ABSTRACT="Sends message from NT to NT or Win9x running winpopup";
5            
6             #use strict;
7 1     1   605 use warnings;
  1         2  
  1         26  
8 1     1   4 use Carp;
  1         2  
  1         111  
9 1     1   10 use Fcntl qw(:DEFAULT :flock);
  1         5  
  1         565  
10            
11             sub new
12             {
13             my ($to,%options)=@_;
14            
15             if ( $^O ne 'MSWin32' ) {
16             carp "ERROR: Invalid. Module only for Windows.";
17             return 0;
18             }
19            
20 1     1   1659 use Win32;
  0            
  0            
21             if (! Win32::IsWinNT()) {
22             carp "ERROR: Invalid. Module only for Windows NT.";
23             return 0;
24             }
25            
26             my $self = {
27             to => $options{to},
28             message => $options{message}
29             };
30             return bless $self;
31             }
32            
33             sub Send
34             {
35             my ($self,%options)=@_;
36            
37             if (exists $options{to}) {
38             $self->{to} = $options{to};
39             }
40            
41             if (exists $options{message}) {
42             $self->{message} = $options{message};
43             }
44            
45             if ( $self->{to} eq "" or $self->{message} eq "" ) {
46             carp "ERROR: Invalid type. You should use to and message";
47             return 0;
48             }
49            
50             # Message... Convert to Unicode
51             my($message_w) = "$self->{message}";
52             $message_w =~ s/./$&\0/g;
53             $message_w .= "\0";
54            
55             # To... Convert to Unicode
56             my($to_w) = "$self->{to}";
57             $to_w =~ s/./$&\0/g;
58             $to_w .= "\0";
59            
60             # Get DLL Function Entry Point
61             use Win32::API;
62             my($NetSend) = new Win32::API('netapi32.dll', 'NetMessageBufferSend', [P,P,P,P,I], I);
63             if(not defined $NetSend) {
64             carp "ERROR: Invalid. Can't import API NetMessageBufferSend:";
65             return 0;
66             }
67            
68             # And Send!!!
69             my($CallNetSend) = $NetSend->Call(
70             0, # Servername
71             "$to_w", # msgName
72             0, # FromName
73             "$message_w", # Buff
74             length("$message_w")); # Length Buff
75            
76             return $CallNetSend;
77             }
78            
79             1;
80            
81             =head1 NAME
82            
83             Win32::NetSend - Sends message from NT to NT or Win9x running winpopup
84            
85             Version 0.2
86            
87             =head1 SYNOPSIS
88            
89             use Win32::NetSend;
90            
91             my $NetSend = Win32::NetSend->new(
92             to => "user",
93             message => "hello world!");
94             $NetSend->Send();
95            
96             Or can use it:
97            
98             my $NetSend = Win32::NetSend->new();
99             $NetSend->Send(
100             to => "user",
101             message => "hello world");
102            
103             =head1 DESCRIPTION
104            
105             This module sends message from NT to NT or Win9x running winpopup.
106            
107             This module is a small and simple Perl GUI utility to send messages
108             via MS LAN Manager to lists of recipients. It works in the same
109             manner as "net send" command.
110            
111             The utility can be used if you need to send the same message to
112             groups of people. For instance, you are going to update some server
113             software and have to ask the users who work with the software to log
114             off.
115            
116             =head1 PLATAFORMS
117            
118             This module work in:
119            
120             Win95 - Only receive if running winpopup
121             Win98 - Only receive if running winpopup
122             WinMe - Only receive if running winpopup
123            
124             WinNT4 - Full support, send an receive
125             Win2000 - Full support, send an receive
126             WinXP - Full support, send an receive
127            
128            
129             =head1 Functions
130            
131             =over 4
132            
133             =item Send
134            
135             Send(
136             to => "user",
137             message => "hello world");
138            
139             Send a message to user, machine, domain. For actual domain use *
140            
141             =back
142            
143             =head1 SEE ALSO
144            
145             B requires L .
146            
147             =head1 STATUS
148            
149             This version (0.02) is a beta version. You can use it but interface may change.
150            
151             =head1 AUTHOR
152            
153             Victor Sanchez
154            
155             =head2 THANKS
156            
157             Thanks to people of Perl-ES ( htpp://perl-es.sf.net )
158            
159             =head1 COPYRIGHT
160            
161             (c) Copyright 2002, 2003 Victor Sanchez
162            
163             This library is free software; you can redistribute it and/or modify it
164             under the same terms as Perl itself.
165            
166             =cut