#  DumpLogonScript.pl
#  Example 6.1:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script displays the logon script path for the specified
#  user accounts.

use Win32;
use Win32::AdminMisc;

if( ! scalar @ARGV )
{
  my( $Script ) = ( $0 =~ /([^\\]*?)$/ );
  print << "EOT";
  Syntax
    perl $Script <User Account> [ <User Account 2> [ ... ] ]

  Example:
    perl $Script administrator 
    perl $Script 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() );
  }
} 
