[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  # Script to set the power management policy
   2  # Written by Justin Beckley
   3  # E-mail - jbeckley@utk.edu
   4  
   5  use warnings;
   6  use strict;
   7  use Getopt::Long;
   8  use Pod::Usage;
   9  
  10  # Store options in a hash for later use
  11  my %opts;
  12  GetOptions (\%opts, 'help|h|?')
  13      or pod2usage (2);
  14  
  15  # If the user needs help, give it
  16  (exists $opts{'help'})
  17      and pod2usage ('-exitstatus' => 0, '-verbose' => 2);
  18  
  19  # Ensure only one argument after the options
  20  scalar @ARGV == 1
  21      or pod2usage (2);
  22  
  23  # Assign the argument to a variable
  24  my $power = $ARGV[0];
  25  
  26  ## Validate options
  27  
  28  # Argument must be 0 - 5
  29  $power =~ /^[012345]$/
  30      or die "Argument must be 0,1,2,3,4, or 5.\n";
  31  
  32  ## Now do some work
  33  
  34  my %reg;
  35  use Win32::TieRegistry (Delimiter => '/', TiedHash => \%reg, qw (REG_SZ));
  36  
  37  my $key = ('HKEY_CURRENT_USER/Control Panel/PowerCfg/');
  38  
  39  my $power_key = $reg{$key};
  40  defined $power_key
  41      or die "Unable to open $key: $^E\n";
  42  
  43  # Write the power configuration to the registry
  44  defined ($power_key->{'/CurrentPowerPolicy'} = $power)
  45      or die "Unable to set CurrentPowerPolicy key: $^E";
  46  
  47  __END__
  48  
  49  =head1 NAME
  50  
  51  powercfg.pl - Specify a power management scheme
  52  
  53  =head1 SYNOPSIS
  54  
  55  powercfg.pl [ options ] 0/1/2/3/4/5
  56  
  57  Options:
  58  
  59  --help    Display verbose help and exit
  60  
  61  =head1 DESCRIPTION
  62  
  63  powercfg.pl allows the user to specify a power management scheme that is
  64  built into windows.
  65  
  66                              Turn Off               System
  67                          ---------------------------------------
  68                          monitor   hard disk    standby  hibernate
  69  
  70    0 - Home/Office Desk - 20 min.   Never       Never     Never
  71    1 - Portable/Laptop  - 15 min.   30 min.     20 min.   3 hrs.
  72    2 - Presentation     - Never     Never       Never     Never
  73    3 - Always On        - 20 min.   Never       Never     Never
  74    4 - Minimal Mngt.    - 15 min.   Never       Never     Never
  75    5 - Max Battery      - 15 min.   Never       20 min.   45 min.
  76  
  77  =head1 SEE ALSO
  78  
  79  Nothing provided yet.


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