this snippet will set a new system environment variable named bob. if you want to create a user environment variable, use the commented out code instead. make sure you understand the difference before you do this blindly. a system environment variable will affect all users on that machine. a user environment variable will affect only that specific user.
#!/usr/bin/perl -w
use strict;
my $Reg;
use Win32::TieRegistry (
TiedRef => \$Reg,
ArrayValues => 1,
Delimiter => '/',
':REG_'
);
# this is the system environment variable area
my $SysEnv= $Reg->{"LMachine/System/CurrentControlSet/Control/" .
"Session Manager/Environment/"}
or die "Can't open Registry key, Session Manager/Environment: $^E
+\n";
# create a new value and set it's data
$SysEnv->{"/bob"} = "test system";
# # this is the user environment variable area
# my $UserEnv= $Reg->{"CUser/Environment/"}
# or die "Can't open Registry key, CUser/Environment: $^E\n";
# # create a new value and set it's data
# $UserEnv->{"/bob"} = "test user";
thanks to tye, as most of this code is pasted from his example here.
~Particle |