#  ConfigLogonScript.pl
#  Example 6.2:
#  ----------------------------------------
#  From "Win32 Perl Scripting: Administrators Handbook" by Dave Roth
#  Published by New Riders Publishing.
#  ISBN # 1-57870-215-1
#
#  This script configures the specified user account to use
#  the specified logon script.

use Win32;
use Win32::AdminMisc;

if( ! scalar @ARGV )
{
    my( $Script ) = ( $0 =~ /([^\\]*?)$/ );
    print << "EOT";
    Syntax:
        perl $Script <User Account> <Logon Script Path>

    Example:
        perl $Script administrator scripts\\administrator.bat
        perl $Script accounting\\joel "genericlogon.pl"

    To remove a logon script set the path to "" as in:
        perl $Script accounting\\joel ""
EOT
    exit();
}

my( $Account, $Path ) = @ARGV;
if( "" eq $Path ) 
{
    print "Removing the logon script for the $Account account.\n";
}
else
{
    print "Configuring the $Account account with a logon script of:\n$Path\n";
}
if( Win32::AdminMisc::UserSetMiscAttributes( '', $Account, USER_SCRIPT_PATH => $Path ) )
{
    print "Successful\n";
}
else
{
    print "An error occured: " . Win32::FormatMessage( Win32::AdminMisc::GetError() );
}

