Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
system() passes the process environment to the child shell process. This environment is stored in the %ENV assoc array. If you need only to change the path for a couple system() calls, just alter $ENV{path}. If you are trying to make a permanent change, it can be done... You have to hack the registry, via the Win32 perl api.

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!)

#!/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"
Alas, I can not claim credit for that one. That goes to Tye. My next goal is to get Tye to join Perl Monks.

In reply to Re: How can I change the environment from within my Perl script? (Adam: edit registry) by Adam
in thread How can I change the environment from within my Perl script? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found