in reply to Setting and changing system variables under win2000

perhaps the following code might give you a key what to do:
#!perl -w use strict; my (%variable) = ( 'EngineConfigDir' => 'c:\Daily\DreBa_Connect_Engine +\Config'); &SetSystemVariable(\%variable); # ------------------------------------------------------------ sub SetSystemVariable { my ($variable) = @_; # well, this should be in the head of your script # I just put it here to complete the function use Win32::TieRegistry( ArrayValues=>0 ); my $pound= $Registry->Delimiter("/"); my $systemVariable = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Control/Session Man +ager/Environment"} or die ("Can't find root\n");; # set systemvariable foreach (keys %$variable){ $systemVariable->{"/$_"} = $variable->{$_}; } my $systemVariable2 = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Control/Session Man +ager/Environment"} or die ("Can't find\n");; foreach my $key (keys %$systemVariable2){ print ("$key => $systemVariable->{$key}\n") if (grep { $key eq + "/$_" } keys %$variable); } } # SetSystemVariable # ------------------------------------------------------------
I used it about two years ago to set an environment variable called EngineConfigDir. But I'm afraid a little bit more error handling is necessary.

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Replies are listed 'Best First'.
Re: Re: Setting and changing system variables under win2000
by NaSe77 (Monk) on Aug 13, 2002 at 13:13 UTC
    I tried your code (as I have already written) and I found some strange things:
  • this code adds the keys to the registry
  • the variables can be seen in the "Variables d'environment" context menu
  • but if i type echo %The_variable_I_changed% i get just %The_variable_I_changed% and not the value
  • in %ENV there is no new key %The_variable_I_changed%

    strange, or?

    Anyone can help?

    ----
    NaSe
    :x

      Try to close the dos-prompt (or cmd.exe or whatever) and reopen it. If that still doesn't work, try to logoff and logon again (or just reboot).

      If the first solution fixes the problem, it might help to add the following line to the code above:

      $ENV{'The_variable_I_changed'} = 'value';
      This will temporarily add the environmentvariable, but will be gone if you close the shell. But if you reopen another, the system variable from the other code now will be accessible instead.

      Sorry, I can't test it because here I don't have access to a Windows-machine in the moment...

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

        You are right after a relogin it works ... thanks so I will do both change the registry and change the %ENV-entry so that it works before and after reboot - thanks a lot

        ----
        NaSe
        :x

Re: Re: Setting and changing system variables under win2000
by NaSe77 (Monk) on Aug 13, 2002 at 12:14 UTC
    thanks a lot this is exactly what i was searching for

    ----
    NaSe
    :x