#  ServiceNames.pl
#  Example 8.1:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script displays all available services.
#
print "From the book 'Win32 Perl Scripting: The Administrator's Handbook' by Dave Roth\n\n";


use Win32::Service;
push( @ARGV, Win32::NodeName() ) unless( scalar @ARGV );
foreach my $Machine ( @ARGV )
{
    local %List;
    print "Available services on $Machine:\n";
    if( Win32::Service::GetServices( $Machine, \%List ) )
    {
        $~ = FormatHeader;
        write;
        $~ = FormatData;
        foreach $Service ( sort( keys( %List ) ) )
        {
            write;
        }
        print "\n" x 3;
    }
    else
    {
        print Win32::FormatMessage( Win32::GetLastError() ), "\n";
    }
}

format FormatHeader =
@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"Service Name", "Service Display Name"
------------------ ----------------------------------------------------------
.

format FormatData =
@<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$List{$Service}, $Service
.
