[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/bin/ -> autolog.pl (source)

   1  # Script to enable or disable automatic logon.
   2  
   3  use warnings;
   4  use strict;
   5  use Getopt::Long;
   6  use Pod::Usage;
   7  
   8  # Your usual option-processing sludge.
   9  my %opts;
  10  GetOptions (\%opts, 'logon=s', 'user=s', 'password=s', 'domain=s',
  11              'keep', 'help')
  12      or pod2usage (2);
  13  
  14  (exists $opts{'help'})
  15      and pod2usage ('-exitstatus' => 0, '-verbose' => 2);
  16  
  17  my %reg;
  18  use Win32::TieRegistry (Delimiter => '/', TiedHash => \%reg);
  19  
  20  my $winlogon_key_name =
  21      'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Winlogon/';
  22  
  23  my $winlogon_key = $reg{$winlogon_key_name};
  24  defined $winlogon_key
  25      or die "Unable to open $winlogon_key_name: $^E";
  26  
  27  my %new_values = ('DefaultUserName' => $opts{'user'},
  28                    'DefaultPassword' => $opts{'password'},
  29                    'AutoAdminLogon' => $opts{'logon'},
  30                    'DefaultDomainName' => $opts{'domain'}
  31                    );
  32  
  33  foreach my $name (sort keys %new_values) {
  34      my $val = $new_values{$name};
  35      if (defined $val) {
  36          $winlogon_key->SetValue ($name, $val)
  37              or die "Unable to set $winlogon_key_name/$name to $val: $^E";
  38      }
  39      elsif (!$opts{'keep'}) {
  40          (delete $winlogon_key->{"/$name"})
  41              or die "Unable to delete $winlogon_key_name/$name: $^E";
  42      }
  43      # else do nothing
  44  }
  45  
  46  __END__
  47  
  48  =head1 NAME
  49  
  50  autolog.pl - Set defaults for Windows logon
  51  
  52  =head1 SYNOPSIS
  53  
  54  autolog.pl [ options ]
  55  
  56  Options (may be abbreviated):
  57  
  58   --help                 Display help and exit
  59   --user=<username>      Set user name field to <username>
  60   --password=<password>  Set password field to <password>
  61   --domain=<domain>      Set domain to <domain>
  62   --logon=<val>          Set AutoAdminLogon key to <val>
  63   --keep                 Keep current setting for unspecified entries
  64  
  65  =head1 NOTES
  66  
  67  This script modifies the registry entries controlling automatic logon.
  68  These also control the default user name and domain name in the logon
  69  panel, even when automatic logon is disabled.
  70  
  71  Failing to specify an argument removes the corresponding registry key,
  72  unless the --keep option is provided.  You probably at least want to
  73  specify --logon=0, because otherwise Windows will not even set the
  74  defaults to be the last user who logged on.
  75  
  76  Note that all of these values, most notably the password, are stored
  77  as cleartext.
  78  
  79  Also note that if the password is not set, the automatic logon will
  80  still work if the account has an empty password.  However, Windows
  81  will "helpfully" set the AutoAdminLogon key back to 0 in this case,
  82  disabling automatic logon for next time.
  83  
  84  =head1 EXAMPLES
  85  
  86  To automatically log on to the local machine as user "Administrator"
  87  with password "sekrit":
  88  
  89    autolog.pl --logon=1 --user=Administrator --password=sekrit
  90  
  91  To set the defaut user name and domain to MYDOM\someuser:
  92  
  93    autolog.pl --logon=0 --user=someuser --domain=MYDOM
  94  
  95  To disable automatic logon and clear the defaults, but allow Windows
  96  to set the defaults in the future:
  97  
  98    autolog.pl --logon=0
  99  
 100  To disable all memory of who logged on last, so the the user name must
 101  be typed every time:
 102  
 103    autolog.pl
 104  
 105  =head1 SEE ALSO
 106  
 107    <http://support.microsoft.com/?kbid=234562>


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1