Reputation: 39
Win32::Env
module is used for environment variable set for temporary basis.
I need to set permanently, please help
Please help me to set as permanent . Because i want it use in another exe.
use Win32::Env;
SetEnv(ENV_USER, 'AUTO_EXCEL_EXPORT', 'TRUE');
By this code, i can set environment variable in windows only as temporary. when i check with echo command of that variable it is not showing. because it is set as semi permanent value.
Upvotes: 3
Views: 373
Reputation: 39
use Win32::Env;
SetEnv(ENV_USER, 'AUTO_EXCEL_EXPORT', 'FALSE');
BroadcastEnv();
print "\n";
DelEnv(ENV_USER, 'AUTO_EXCEL_EXPORT');
print "\n";
SetEnv(ENV_USER, 'AUTO_EXCEL_EXPORT', 'TRUE');
BroadcastEnv();
if i run this code its setting only first ENV ( false ) value, in echo command why??????
Upvotes: 0
Reputation: 9296
When assigning/changing environment variables in Windows, the Explorer subsystem needs to be notified that the changes occurred before newly opened windows/applications see the changes. If this doesn't happen, then a reboot is necessary before other processes will see the changes.
As you can see in the SYNOPSIS of Win32::Env, they've got a call to BroadcastEnv() which performs said notification task.
After reviewing the module's code, the author is setting the variables within the registry, so that call should correct the issue. Note though, that if you're running things from a cmd
window while running your script, no matter what, you have to close that window and open a new one for the changes to take effect. All new windows should get the updated environment.
Example:
use Win32::Env;
SetEnv(ENV_USER, 'AUTO_EXCEL_EXPORT', 'TRUE');
BroadcastEnv();
Upvotes: 2