#  PagerClient.pl
#  Example 8.10:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script is a the pager client to Example 8.10 (PagerDaemon.pl).
#
print "From the book 'Win32 Perl Scripting: The Administrator's Handbook' by Dave Roth\n\n";


use Win32::NetAdmin;

# The equivilent to USER_SERVICE_BITS_1
$Service = 0x00004000;

$Domain = Win32::DomainName();
Win32::NetAdmin::GetDomainController( '', $Domain, $Pdc );
if( Win32::NetAdmin::GetServers( $Pdc, $Domain, $Service, \@List )
     && ( scalar @List ) )
{
    # Just try the first server in the list
    if( open( PAGER, "> \\\\$List[0]\\pipe\\PagerService" ) )
    {
        my $BackupHandle = select( PAGER );
        $| = 1;
        select( $BackupHandle );
        print "Submitting page...\n";
        print PAGER "$ARGV[0]\t$ARGV[1]\t$ARGV[2]\n";
        close( PAGER );
    }
}
