#  DumpLogonScript.pl
#  Example 5.1:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script is displays the logon script path for the specified
#  user accounts.

use Win32;
use Win32::AdminMisc;

if( ! scalar @ARGV )
{
    print << "EOT";
    Syntax
        perl $0 <User Account> [ <User Account 2> [ ... ] ]

    Example:
        perl $0 administrator 
        perl $0 somedomain\\administrator accounting\\joel 
EOT

    exit();
}

foreach my $Account ( @ARGV )
{
    my %Info;

    print "$Account logon script: ";
    if( Win32::AdminMisc::UserGetMiscAttributes( '', $Account, \%Info ) )
    {
        if( "" eq $Info{USER_SCRIPT_PATH} )
        {
            $Info{USER_SCRIPT_PATH} = "No logon script configured";
        }
        print "$Info{USER_SCRIPT_PATH}\n";
    }
    else
    {
        print Win32::FormatMessage( Win32::AdminMisc::GetError() );
    }
}