[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  
   2  use warnings;
   3  use strict;
   4  use Getopt::Long;
   5  use Pod::Usage;
   6  use Win32::OLE;
   7  
   8  # Your usual option-processing sludge.
   9  my %opts;
  10  GetOptions (\%opts, 'help|h|?', 'remote=s', 'user=s')
  11      or pod2usage (2);
  12  
  13  (exists $opts{'help'})
  14      and pod2usage ('-exitstatus' => 0, '-verbose' => 2);
  15  
  16  # Ensure exactly two arguments after options.
  17  scalar @ARGV == 2
  18      or pod2usage (2);
  19  
  20  my ($var_name, $value) = @ARGV;
  21  
  22  # Bomb out completely if COM engine encounters any trouble.
  23  Win32::OLE->Option ('Warn' => 3);
  24  
  25  # Get a handle to the SWbemServices object of the machine.
  26  my $computer = Win32::OLE->GetObject (exists $opts{'remote'}
  27                                        ? "WinMgmts://$opts{'remote'}/"
  28                                        : 'WinMgmts:');
  29  
  30  # Get the environment variable class object.  See:
  31  # <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_environment.asp>
  32  my $var_class = $computer->Get ('Win32_Environment');
  33  
  34  # Create an instance of this class.
  35  my $var = $var_class->Spawninstance_ ();
  36  
  37  # Set the instance's properties appropriately.
  38  $var->{'Name'} = $var_name;
  39  $var->{'Username'} = exists $opts{'user'} ? $opts{'user'} : '<SYSTEM>';
  40  $var->{'VariableValue'} = $value;
  41  
  42  $var->Put_();
  43  
  44  exit 0;
  45  
  46  __END__
  47  
  48  =head1 NAME
  49  
  50  setenv.pl - Set a Windows environment variable
  51  
  52  =head1 SYNOPSIS
  53  
  54  setenv.pl [ options ] <variable> <value>
  55  
  56  Options (may be abbreviated):
  57  
  58   --help                 Display help and exit
  59   --remote <host>        Set variable on <host> instead of local machine
  60   --user <user>          Set variable for <user> (default "<SYSTEM>")
  61  
  62  =head1 NOTES
  63  
  64  The --user switch may be a user name or one of the special strings
  65  "<DEFAULT>" and "<SYSTEM>".
  66  
  67  =head1 SEE ALSO
  68  
  69  C<http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_environment.asp>


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