[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  # Shut down a Windows workstation.
   2  
   3  use warnings;
   4  use strict;
   5  use Getopt::Long;
   6  use Pod::Usage;
   7  use Win32API::Registry qw(:Func :SE_);
   8  
   9  # Your usual option-processing sludge.
  10  my %opts;
  11  GetOptions (\%opts, 'help|h|?', 'message=s', 'halt', 'reboot|r',
  12              'remote=s', 'timeout=i')
  13      or pod2usage (2);
  14  
  15  (exists $opts{'help'})
  16      and pod2usage ('-exitstatus' => 0, '-verbose' => 2);
  17  
  18  # Ensure no arguments after options
  19  @ARGV == 0
  20      or pod2usage (2);
  21  
  22  (exists $opts{'halt'} != exists $opts{'reboot'})
  23      or die "$0: You must specify exactly one of --halt or --reboot\n";
  24  
  25  my $timeout = (exists $opts{'timeout'} ? $opts{'timeout'} : 10);
  26  my $reboot = exists $opts{'reboot'};
  27  my $message = (exists $opts{'message'} ? $opts{'message'}
  28                 : "$0 is shutting down the system");
  29  
  30  my $system = (exists $opts{'remote'} ? $opts{'remote'} : '');
  31  
  32  # Enable "shutdown" privilege
  33  AllowPriv (SE_SHUTDOWN_NAME, 1)
  34      or die "Unable to AllowPriv SE_SHUTDOWN_NAME: $^E";
  35  
  36  InitiateSystemShutdown ($system, $message, $timeout, 1, $reboot)
  37      or die "Unable to InitiateSystemShutdown: $^E";
  38  
  39  print "Shutdown initiated.\n";
  40  
  41  exit 0;
  42  
  43  __END__
  44  
  45  =head1 NAME
  46  
  47  shutdown.pl - Shut down a Windows system
  48  
  49  =head1 SYNOPSIS
  50  
  51  shutdown.pl [ options ]
  52  
  53  =head1 OPTIONS
  54  
  55   --help                  Display help and exit
  56   --message=<msg>         Display <msg> in message box during countdown
  57   --halt                  Shut down and halt
  58   --reboot                Shut down and reboot
  59   --remote <host>         Shut down <host> instead of local machine
  60   --timeout=<secs>        Wait <secs> seconds before shutdown (default 10)


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