[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  # Set startup type (automatic, manual, etc.) for a service
   2  
   3  use warnings;
   4  use strict;
   5  use Win32::OLE;
   6  
   7  @ARGV == 2
   8      or die "Usage: $0 <type> <service>\n";
   9  
  10  my ($type, $service_name) = @ARGV;
  11  # Convert to lower-case
  12  $type = lc $type;
  13  $service_name = lc $service_name;
  14  
  15  my %types = map { (lc $_ => $_) } ('Boot', 'System', 'Automatic',
  16                                             'Manual', 'Disabled');
  17  
  18  (exists $types{$type})
  19      or die '<type> must be one of ', join ' ', keys %types;
  20  
  21  # Bomb out completely if COM engine encounters any trouble.
  22  Win32::OLE->Option ('Warn' => 3);
  23  
  24  # Get a handle to the SWbemServices object of the local machine.
  25  my $computer = Win32::OLE->GetObject ('WinMgmts:');
  26  
  27  # Get the SWbemObjectSet of all services.  See:
  28  # http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_service.asp
  29  my $services_set = $computer->InstancesOf ('Win32_Service');
  30  
  31  # Convert set to a Perl array.
  32  my @services = Win32::OLE::Enum->All ($services_set);
  33  
  34  foreach my $service (@services) {
  35      my $name = $service->{'Name'};
  36      my $display_name = $service->{'DisplayName'};
  37      if (($service_name eq lc $name)
  38          || ($service_name eq lc $display_name)) {
  39          print "Setting mode for $name ($display_name) to $types{$type}...";
  40          my $ret = $service->ChangeStartMode ($types{$type});
  41          $ret == 0
  42              or die "Unable to ChangeStartMode to $types{$type}: $ret";
  43          print "done.\n";
  44          exit 0;
  45      }
  46  }
  47  
  48  die "Could not find service $service_name.\n";


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