⭐ in reply to How can I change the environment from within my Perl script?
If I remember to, I will post some sample code explaining how to do this, but I don't remember the exact syntaxes off hand. I suppose I also aught to point out that you hack the Win32 registry at your own (rather probable) risk. Do not tread there lightly. That said, you just change the key in the registry that stores the path. I'll have to look up the key name for you too.
UPDATE: As promised, I have pursued this further for you. Struggling to remember how I did it, I remembered that I didn't... I used a subroutine that a co-worker of mine had written. So I asked him how he did it, and his response was, "Well the best way to do it is with the Win32::TieRegistry module that I wrote" (paraphrase). He was even kind enough to show me how to use it; here is the code that he gave me (disclaimer: muck with Win32 registry at own risk!)
Alas, I can not claim credit for that one. That goes to Tye. My next goal is to get Tye to join Perl Monks.#!/usr/bin/perl -w use strict; my $Registry; use Win32::TieRegistry ( TiedRef=>\$Registry, Delimiter=>"/", ArrayVal +ues=>1 ); my $env= $Registry->{"LMachine/System/CurrentControlSet/Control/". "Session Manager/Environment/"} or die "Can't open CCS/SM/Env: $^E\n"; my $path= $env->{"/PATH"} or die "Can't get PATH: $^E\n" $path->[0]= "C:\Perl\bin;$path->[0]"; $env->{"/PATH"}= $path or die "Can't set PATH: $^E\n"
|
---|