[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  # Script to enable/disable system restore.
   2  
   3  use warnings;
   4  use strict;
   5  use Getopt::Long;
   6  use Pod::Usage;
   7  use Win32::OLE;
   8  
   9  my $me = 'srconfig.pl';
  10  
  11  # Your usual option-processing sludge.
  12  my %opts;
  13  GetOptions (\%opts, 'help|h|?', 'remote=s', 'enable', 'disable')
  14      or pod2usage (2);
  15  
  16  (exists $opts{'help'})
  17      and pod2usage ('-exitstatus' => 0, '-verbose' => 2);
  18  
  19  # Ensure no arguments after options.
  20  scalar @ARGV == 0
  21      or pod2usage (2);
  22  
  23  ($opts{'enable'} || $opts{'disable'})
  24      or die "$me: You must specify one of --enable or --disable; bailing";
  25  
  26  ($opts{'enable'} && $opts{'disable'})
  27      and die "$me: You must specify only one of --enable or --disable; bailing";
  28  
  29  # Bomb out completely if COM engine encounters any trouble.
  30  Win32::OLE->Option ('Warn' => 3);
  31  
  32  # Get a handle to the SWbemServices object of the machine.
  33  my $computer = Win32::OLE->GetObject
  34      (exists $opts{'remote'}
  35       ? "WinMgmts://$opts{'remote'}/root/default"
  36       : 'WinMgmts:root/default');
  37  
  38  # Run a query to find the SystemRestore class object.  See
  39  # <http://msdn.microsoft.com/library/en-us/sr/sr/systemrestore.asp>
  40  # and
  41  # <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/select_statement_for_schema_queries.asp>.
  42  # We do it this way because the class only exists on XP and later.
  43  
  44  my $sr_set = $computer->ExecQuery ('SELECT * from meta_class WHERE __this ISA "SystemRestore"');
  45  
  46  # Convert set to Perl array.
  47  my @srs = Win32::OLE::Enum->All ($sr_set);
  48  
  49  if (scalar @srs < 1) {
  50      print "$me: SystemRestore class not found; nothing to do.\n";
  51      exit 0;
  52  }
  53  
  54  my $sr = $srs[0];
  55  
  56  if ($opts{'disable'}) {
  57      print 'Disabling System Restore...';
  58      $sr->Disable ('');
  59      print "done.\n";
  60  }
  61  elsif ($opts{'enable'}) {
  62      print 'Enabling System Restore...';
  63      $sr->Enable ('');
  64      print "done.\n";
  65  }
  66  else {
  67      die 'Internal error';
  68  }
  69  
  70  exit 0;
  71  
  72  =head1 NAME
  73  
  74  srconfig.pl - Enable/disable System Restore
  75  
  76  =head1 SYNOPSIS
  77  
  78  srconfig.pl [ options ]
  79  
  80  Options (may be abbreviated):
  81  
  82   --help                 Display help and exit
  83   --remote <host>        Operate on <host> instead of local machine
  84   --disable              Disable system restore
  85   --enable               Enable system restore
  86   
  87  =head1 NOTES
  88  
  89  This script enables or disables the "System Restore" feature
  90  introduced in Windows XP.  If run on an earlier version of Windows, it
  91  prints a short message and exits successfully.
  92  
  93  =head1 SEE ALSO
  94  
  95  C<http://msdn.microsoft.com/library/en-us/sr/sr/systemrestore.asp>
  96  C<http://support.microsoft.com/?kbid=295299>


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