Setting Environment Variables

R

Rick Kasten

Here's what I need to do:

1) Write "Password:" to the console
- I know how to do that
2) Accept input that is not written back to the console
- I know how to do that (Term::ReadKey)
3) Set the PASSWD variable so that when the script exits, my env
variables now include one called PASSWD that contains the text I typed
at the "Password:" prompt.
- what I need help with

Any assistance? I'm sure this is an easy one...
 
J

Jürgen Exner

Rick said:
Here's what I need to do: [...]
3) Set the PASSWD variable so that when the script exits, my env
variables now include one called PASSWD that contains the text I typed
at the "Password:" prompt.

Any assistance? I'm sure this is an easy one...

Not exactly easy, more like impossible. See the FAQ
perldoc -q env:
I {changed directory, modified my environment} in a perl script. How
come the change disappeared when I exited the script? How do I get my
changes to be visible?

jue
 
H

Howard

3) Set the PASSWD variable so that when the script exits, my env
variables now include one called PASSWD that contains the text I typed
at the "Password:" prompt.
- what I need help with


Rick, are you setting this in a win32 environment? If so, you can
use the Win32::Registry to set the variable. The key I've used to set
variables is:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment

Some sample code is:
use Win32::Registry;
$p = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment";
$HKEY_LOCAL_MACHINE->Open($p, $CurrVer) || die "Open $!";

And you can either create and set or just set a value.

key->Create($newkey, name)
key->SetValue(subkey, type, value)

Hope this helps.

Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top